Reputation: 2131
I know how local directories can be mounted as volumes with the -v
option in docker run
, i.e.
docker run -v /local/some_folder:/container/some_folder image_name
However, I want to be able to specify the above instruction (to mount the local /local/some_folder
as /container/some_folder
in the container within the Dockerfile.
I've tried using VOLUME /local/some_folder /container/some_folder
in the Dockerfile
, but that didn't seem to work: I am then able to access /container/some_folder
from within the container using docker exec -t container sh
, but the write changes of container to /container/some_folder
are not reflected in /local/some_folder
during container runtime AND after docker stop container
.
Upvotes: 5
Views: 5113
Reputation: 265075
You do not have access to control things like host volume mounts inside the Dockerfile or image build process. Allowing this would allow malicious image creators to make an image that mounts directories on the host without the permission of the admin of that host. A security breach that allowed a popular base image to mount the filesystem could be used to send private data off-site and inject login credentials on countless machines. The only way to mount a volume is at run time at the explicit request of the admin running the container, and to the directory they provide.
Upvotes: 5