Dockerfile docker volume recording not working

Pay attention to the following Docker file:

FROM phusion/baseimage VOLUME ["/data"] RUN touch /data/HELLO RUN ls -ls /data 

Problem: the "/ data" directory does not contain the "HELLO" file. Moreover, any other attempts to write to the volume directory (via echo, mv, cp, ...) were unsuccessful - the directory is always empty. Error messages are not displayed.

I could not find anything in the documentation or in stackoverflow regarding this problem.

Is this something famous or new?

docker version returns:

 Client version: 1.2.0 Client API version: 1.14 Go version (client): go1.3.1 Git commit (client): fa7b24f OS/Arch (client): linux/amd64 Server version: 1.2.0 Server API version: 1.14 Go version (server): go1.3.1 Git commit (server): fa7b24f 
+8
docker volume
source share
1 answer

Each Dockerfile step is launched in its own container, which is discarded when this step is executed, and volumes are discarded when the last (only in this case) container that uses them is deleted after the command completes. This makes files poorly suited for use in Dockerfiles because they lose their contents halfway. Docker files are designed to work anywhere, and if they used volumes that were saved, that would make it more complicated. On the other hand, if you really want to, just return the directory volume on the host.

PS: Initializing the host data directory is best done outside of the Docker file.

The last time I needed this, I left this step from the docker file, because the idea of ​​this step is to prepare the host to run the image created by this Docker file. Then I made a container with launching dockers and inside this container I launched a regular database configuration file.

 docker run -v /var/lib/mysql:/raid/.../mysql ... /usr/bin/mysql_install_db mysql_secure_installation 

Now, when this container is moved to a new host, this data directory can be either with it or created using the same process on this host. Or if, as in my example, you need another mysql db for another application, you do not need to repeat the creation of the container.

An important idea is to keep the container settings and the host settings separate.

+8
source share

All Articles