It might be helpful to create a container that has nothing. Nothing means nothing.
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
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.
Inspired on @BMitch's answer, the solution is that the Dockerfile
can not only contain the FROM
sentence.
It compiles, but fails when doing a docker create
, the engine complains because it does not have a command even if it's a create and not a run.
The complete Dockerfile is this one:
FROM scratch
CMD ""
You can build it (in my case I named the image xavi-scratch
) and then see the image is 0 bytes of data:
$ docker image ls | grep xavi-scratch
xavi-scratch latest bee1419a6d83 N/A 0B
I then create a container without running it:
docker create -v ${PWD}/whatever-dir:/data --name test-scratch xavi-scratch
There's a full session here testing it serves the purpose:
a
and b
and create one file in a
.b
is emptyb
.a
into the containerb
contains the file copied via the container.