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)
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With