Conversation
Current VOLUME command in a Dockerfile cannot bind mount with a host directory. Add support it to the VOLUME command too so that users can specify something like below in their Dockerfile: VOLUME /this/is/host/dir:/container/foo VOLUME /another/host/dir:/container/bar:ro Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@gmail.com>
97d6b6c to
d9d7fdd
Compare
|
Making a change to allow bind mounts from the Dockerfile would allow images to bind mount arbitrary directories and files from the host by default. NOT LGTM |
|
NOT LGTM |
|
I'm closing this now because it's not going to be merged for very good reasons:
|
|
@unclejack and @cpuguy83 : I would like to discuss this usecase a little further and request your suggestion on this. Let's say I want to create an image for MySQL and so I have a "RUN apt-get -y install mysql-server" in my Dockerfile. When building the image MySQL creates a data directory /var/lib/mysql in the image. This data directory contains some metadata required for MySQL to start. However, I later want to store the data in a mounted volume and not store it directly in the container. So, when I later run a container using this image, I have to somehow pull out the installed directory into a hosted volume because, without this, I won't be able to start MySQL. (in other words I cannot mount a blank directory as /var/lib/mysql/). So I now have 2 choices:
I am sure most databases' data directories work in a similar way and this page in the Docker documentation clearly lists that Docker does recommend mechanisms to mount db data directories externally: https://docs.docker.com/userguide/dockervolumes/#creating-and-mounting-a-data-volume-container I am not suggesting that this patch is the way to go and I clearly understand the issues outlined by @unclejack. However, I am not sure what's the right way of doing this. Request your suggestion. |
|
@buzypi |
|
@cpuguy83 Oh cool, I didn't know that. Let me try this. I thought Docker mounts are like OS filesystem mounts where a mount will hide the host directory at the same location. |
|
@cpuguy83 |
|
@buzypi Well, i started using Docker @ 0.6.5, and ever since then at least. The way volumes work is when you "-v /foo", docker creates a dir on the host. Docker copies that data that was in "/foo" (if any exists, or creates /foo if /foo didn't already exist) into the new dir on the host, then mounts that host dir into the container at /foo. |
|
@cpuguy83 Agreed, but then this does not allow me to host a directory of my choice. I see that this is inside /var/lib/docker/vfs/dir/. Is there a way to mount a host directory of our own and also copy data during the initial run? |
|
@buzypi Docker will specifically not copy data into a user specified dir (for now). |
|
@cpuguy83 So for now the workaround seems to be this: And then discard |
|
Yep, I do this frequently (or something close to it) for config files and such. |
|
@cpuguy83 Ok thanks. That seems like a good enough solution for now. |
@cpuguy83 I was looking for the same recently. Is there a proposal for that, so that I can give my +1 on that? |
|
@thaJeztah No proposal as such. |
This patch adds support to bind mount for VOLUME command in Dockerfile. AFAIK currently a volume only can be bind-mounted with docker run command (-v option), but with this change, one can use VOLUME command in a Dockerfile to specify such bind mount when building an image too.