Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create a pure data image in docker

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)

like image 307
Bo Chen Avatar asked Oct 17 '16 15:10

Bo Chen


People also ask

Can you Dockerize a database?

Docker is great for running databases in a development environment! You can even use it for databases of small, non-critical projects which run on a single server.

Does Docker image contain data?

A Docker image is an immutable (unchangeable) file that contains the source code, libraries, dependencies, tools, and other files needed for an application to run. Due to their read-only quality, these images are sometimes referred to as snapshots.


Video Answer


1 Answers

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
like image 178
Elton Stoneman Avatar answered Sep 20 '22 16:09

Elton Stoneman