14

I know that in docker we can run data volume containers like this

#create a pure data container based on my data_image
docker run -v /data   --name data-volume-container   data-vol-container-img

# here I'm using the data volume in a property container (ubuntu)
docker run --volumes-from data-volume-container     ubuntu

my question is how do we create the data_image?

I know that the easiest way is to create a image based on ubuntu, or anything like that

From ubuntu
Copy data /data
CMD["true"]

But the thing is , why do I need ubuntu as my base image??? (I know it's not a big deal as ubuntu is going to re-used in other scenarios). I really want to know why can't I use scratch??

FROM scratch
COPY data /data
#I don't know what to put here
CMD ["???"]

The image i'm creating here is meant to be a dummy one, it execute absolutely NOTHING and only act a dummy data container, i.e to be used on in docker run -v /data --name my_dummy_data_container my_dummy_data_image

Any ideas??
(Is it because scratch doesn't implement a bare minimum file system? But Docker can use the host system's file system if a container doesn't implement its own)

nwinkler
  • 52,665
  • 21
  • 154
  • 168
Bo Chen
  • 717
  • 1
  • 9
  • 16
  • 1
    Note that "data volume containers" are now considered to be deprecated, since the docker api has support for managing volumes as first-class objects. That is, you can run things like "docker volume create", "docker volume ls", etc. – larsks Oct 17 '16 at 17:47
  • 2
    thanks @larks . the volume created via docker volume create doesn't contain anything, so you still need a container to put content there and then share with others. That's what data volume container is for: the docker image that the volume container is based upon, has some built in content, so that when the data container is used by other application containers, the content is already available – Bo Chen Oct 18 '16 at 00:40

1 Answers1

21

Yes, you can do this FROM scratch.

A CMD is required to create a container, but Docker doesn't validate it - so you can specify a dummy command:

FROM scratch
WORKDIR /data
COPY file.txt .
VOLUME /data
CMD ["fake"]

Then use docker create for your data container rather than docker run, so the fake command never gets started:

> docker create --name data temp
55b814cf4d0d1b2a21dd4205106e88725304f8f431be2e2637517d14d6298959

Now the container is created so the volumes are accessible:

> docker run --volumes-from data ubuntu ls /data
file.txt
Elton Stoneman
  • 17,906
  • 5
  • 47
  • 44