{"action":"created","issue":{"url":"https://api.github.com/repos/docker/docker/issues/26872","repository_url":"https://api.github.com/repos/docker/docker","labels_url":"https://api.github.com/repos/docker/docker/issues/26872/labels{/name}","comments_url":"https://api.github.com/repos/docker/docker/issues/26872/comments","events_url":"https://api.github.com/repos/docker/docker/issues/26872/events","html_url":"https://github.com/docker/docker/issues/26872","id":178956699,"number":26872,"title":"[FEATURE] Access container directory on the host","user":{"login":"milosivanovic","id":1274505,"avatar_url":"https://avatars.githubusercontent.com/u/1274505?v=3","gravatar_id":"","url":"https://api.github.com/users/milosivanovic","html_url":"https://github.com/milosivanovic","followers_url":"https://api.github.com/users/milosivanovic/followers","following_url":"https://api.github.com/users/milosivanovic/following{/other_user}","gists_url":"https://api.github.com/users/milosivanovic/gists{/gist_id}","starred_url":"https://api.github.com/users/milosivanovic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/milosivanovic/subscriptions","organizations_url":"https://api.github.com/users/milosivanovic/orgs","repos_url":"https://api.github.com/users/milosivanovic/repos","events_url":"https://api.github.com/users/milosivanovic/events{/privacy}","received_events_url":"https://api.github.com/users/milosivanovic/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/docker/docker/labels/area/volumes","name":"area/volumes","color":"fbca04"},{"url":"https://api.github.com/repos/docker/docker/labels/kind/enhancement","name":"kind/enhancement","color":"E8CAAF"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2016-09-23T19:33:38Z","updated_at":"2016-09-25T11:39:18Z","closed_at":null,"body":"**Description**\r\n\r\nI have successfully dockerised our entire stack at work, with one caveat:\r\n\r\n- **I need to share a container's directory with the host.**\r\n\r\nI can think of two ways to implement this, in order of preference:\r\n\r\n1. Add an option like `docker run --host-mount /path/on/container:/path/on/host`, which will mount `/path/on/container` to `/path/on/host` after starting the container; or\r\n2. Allow _existing_ named docker volumes (`docker run -v myvol:/path/on/container`) to be mounted to and unmounted from an arbitrary location on the host _at will_, e.g.: `docker volume mount <volname> <mntpoint>`, allowing users to edit files at `<mntpoint>` while the container is running and have those changes reflected immediately at `/path/on/container`.\r\n\r\n**For case number 1**\r\nSince it's already possible to do the reverse (mount a host directory inside a container), I don't see it being difficult to add the ability to share a container directory with the host.\r\n\r\n**For case number 2**\r\nI know that docker volumes are already mounted at `/var/lib/docker/volumes/<volname>/_data` on the host, but this is a system directory and all files are owned by root since this is more of a docker implementation detail than an actual directory you should be doing your day-to-day work in. Therefore, implementing `docker volume mount <volname> <mntpoint>` which will mount a volume to a path on the host and translate permissions to make the files editable by regular users just like `-v` currently does, would be a great solution.\r\n\r\n**Why a host-mounted directory (`-v /path/on/host:/path/on/container`) is insufficient**\r\nI'd like the entire docker container to be self-sufficient in that the Dockerfile has all the instructions necessary to completely automate the setup of the stack, from creating specific directory structures needed for golang, to cloning the many repositories needed for the stack to run, and abstracting any and all dependency management away from the end user. It is all isolated in the container with no previous setup required on the host. By using a host-mounted directory, a directory on the host will be mounted to a directory in the container, which means _the structure for the stack needs to be appropriately set up on the host beforehand_. I'd like all of this to be automated and isolated inside a docker container, apart from the directory exposed to the host, hence this feature request.\r\n\r\n**Why this is needed for my use case**\r\nBy writing a Dockerfile that performs all the necessary setup: creating the correct source code structure, cloning, setting environment variables, dependency management, compiling, and so on, it's extremely easy to set up and tear down our stack completely from scratch. This is invaluable for new employees who just want to start coding and not worry about setting up the correct source code structure needed to make our stack work, since it's all ready to go inside the container.\r\n\r\n**Final words**\r\nThe typical way people set up Dockerfiles would be to `COPY` source code into the containers. As described earlier, this is not ideal for me. One could argue a way around the problem, but my use-case aside, there will be others who need to access container data on the host for other reasons, so this is still a useful feature request that will be appreciated by the community regardless on what is considered \"the Docker way\" to set up your stack.\r\n\r\n**Steps to reproduce the issue:**\r\n1. Create docker container\r\n2. Look for ways to share a container directory with the host\r\n3. Realise this isn't implemented"},"comment":{"url":"https://api.github.com/repos/docker/docker/issues/comments/249416877","html_url":"https://github.com/docker/docker/issues/26872#issuecomment-249416877","issue_url":"https://api.github.com/repos/docker/docker/issues/26872","id":249416877,"user":{"login":"milosivanovic","id":1274505,"avatar_url":"https://avatars.githubusercontent.com/u/1274505?v=3","gravatar_id":"","url":"https://api.github.com/users/milosivanovic","html_url":"https://github.com/milosivanovic","followers_url":"https://api.github.com/users/milosivanovic/followers","following_url":"https://api.github.com/users/milosivanovic/following{/other_user}","gists_url":"https://api.github.com/users/milosivanovic/gists{/gist_id}","starred_url":"https://api.github.com/users/milosivanovic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/milosivanovic/subscriptions","organizations_url":"https://api.github.com/users/milosivanovic/orgs","repos_url":"https://api.github.com/users/milosivanovic/repos","events_url":"https://api.github.com/users/milosivanovic/events{/privacy}","received_events_url":"https://api.github.com/users/milosivanovic/received_events","type":"User","site_admin":false},"created_at":"2016-09-25T11:39:18Z","updated_at":"2016-09-25T11:39:18Z","body":"@AkihiroSuda Excellent find! I've confirmed that, on Linux, `sudo bindfs --map=root/milos /var/lib/docker/volumes/volname/_data /mntpoint` will mount the `volname` volume to `/mntpoint` on the host and ensure any files owned by root in the container (which is all of them, in my case) seem as if they are owned by milos. Both creating and deleting files inside `/mntpoint` works flawlessly without the need for root, and the changes are immediately visible in the container as expected.\r\n\r\nI'd still like to see this functionality bundled with docker, but this is a great temporary workaround. The only real problem now is that myself and my colleagues use Docker for Mac, which actually proxies everything through a virtual machine running Alpine Linux on the xhyve hypervisor, which means `/var/lib/docker` is located on that virtual machine and not on OS X. So, I can't use the `bindfs` solution with Docker for Mac unless someone could explain a way for me to make it work.\r\n\r\nIf it's more appropriate, I can open a GitHub issue at docker/for-mac."}}
{"actor":{"display_login":"milosivanovic"}}