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.
Arthur ulfeldt
source share