-1

It might be helpful to create a container that has nothing. Nothing means nothing.

Use case

In this answer https://stackoverflow.com/a/55683656/1315009 a container is created without ever starting it just to instantiate a volume and copy contents into the volume. Then the container is removed.

The example instantiates a busybox. Nevertheless the busybox contents are never used. So I tested it with the hello-world and it works as well, thus reducing from 1.22MB to 13.3kB.

At the time being, pulling "scratch" fails:

$ docker pull scratch
Using default tag: latest
Error response from daemon: 'scratch' is a reserved name

So... Question

How can I create a container with an image that has "nothing" inside?

I mean similar to docker create hello-world but without the hello-world binary.

Xavi Montero
  • 9,239
  • 7
  • 57
  • 79

1 Answers1

1

A container is defined from an image and includes the command to run inside the container. A container that is just scratch has no commands to run and is therefore not a properly defined container. You can build an image that is nothing more than:

FROM scratch

However, you will quickly run out of things to do with the resulting image. If you need to manage a named volume, that volume will be attached to a container, and that container will use an image, so it's easiest to use that image directly.

BMitch
  • 231,797
  • 42
  • 475
  • 450
  • The thing is we just want team-A to "prepare" some volumes with pre-filled read-only data, so when team-B runs their containers, they have the data there. Team-A does not have access to the images of Team-B. We do not want to pollute the host file-system. So the best way is to "prepare" volumes the same way anyone could prepare "hard disks with info" without having the final PC on which the disk will be consumed. This is why we want "a mechanism" to pre-fill volumes. – Xavi Montero May 04 '20 at 00:27
  • About not having a command, as I told in the question, that's the point: It'll be a container that will **never** surpass the state of `created` and will never start running. Do I need keys of a door that will never open? Same way: Do I need an ENTRYPOINT or CMD for an image that will be never run, just created but not run? – Xavi Montero May 04 '20 at 00:30
  • On the other hand you state "You can build an image that is nothing more than FROM scratch" and the sentence is not correct: If you do that, the builder says: "No image was generated. Is your Dockerfile empty?" This is the reason for the question: What's the "bare minimum" image that is creatable? Why "scratch" created a layer in older versions of docker and does not create a layer in newer versions? – Xavi Montero May 04 '20 at 00:32
  • @XaviMontero I had only tested with buildkit, which does create a scratch image. You could put a label in the image to avoid this error in the classic builder. But overall, this feels like a premature optimization. You could create an image with the volume initialization steps that may be a few megs, and then delete that image when done. You're already downloading lots of other files just to install the docker engine. – BMitch May 04 '20 at 01:05