{"action":"created","issue":{"url":"https://api.github.com/repos/docker/compose/issues/2060","labels_url":"https://api.github.com/repos/docker/compose/issues/2060/labels{/name}","comments_url":"https://api.github.com/repos/docker/compose/issues/2060/comments","events_url":"https://api.github.com/repos/docker/compose/issues/2060/events","html_url":"https://github.com/docker/compose/issues/2060","id":106796087,"number":2060,"title":"question: container writes files that appear on host as owned by root","user":{"login":"rosskevin","id":136564,"avatar_url":"https://avatars.githubusercontent.com/u/136564?v=3","gravatar_id":"","url":"https://api.github.com/users/rosskevin","html_url":"https://github.com/rosskevin","followers_url":"https://api.github.com/users/rosskevin/followers","following_url":"https://api.github.com/users/rosskevin/following{/other_user}","gists_url":"https://api.github.com/users/rosskevin/gists{/gist_id}","starred_url":"https://api.github.com/users/rosskevin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rosskevin/subscriptions","organizations_url":"https://api.github.com/users/rosskevin/orgs","repos_url":"https://api.github.com/users/rosskevin/repos","events_url":"https://api.github.com/users/rosskevin/events{/privacy}","received_events_url":"https://api.github.com/users/rosskevin/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/docker/compose/labels/kind/question","name":"kind/question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-09-16T15:19:17Z","updated_at":"2015-09-16T18:17:16Z","closed_at":null,"body":"I'm looking for some pointers/docs/references to understand a bit more about how to setup docker-compose so that the container doesn't write files on the host owned by root.\r\n\r\nDockerfile\r\n```\r\nFROM atlashealth/ruby:2.2.2\r\n...\r\nCOPY . /project\r\nWORKDIR /project\r\n```\r\n\r\nMy compose container runs a rails test suite, which writes files to the `target` directory.  On the ubuntu host, these appear as owned by `root`, though the container was executed as a non-privileged `apps` user:\r\n ```\r\n# On the host\r\n$ ls -la target/test-reports/\r\ntotal 8\r\ndrwxr-xr-x 2 root root 4096 Sep 15 17:44 .\r\ndrwxr-xr-x 3 root root 4096 Sep 15 17:44 ..\r\n-rw-r--r-- 1 root root    0 Sep 15 17:44 rspec2.xml\r\n-rw-r--r-- 1 root root    0 Sep 15 17:44 rspec3.xml\r\n-rw-r--r-- 1 root root    0 Sep 15 17:44 rspec4.xml\r\n-rw-r--r-- 1 root root    0 Sep 15 17:44 rspec5.xml\r\n-rw-r--r-- 1 root root    0 Sep 15 17:44 rspec6.xml\r\n-rw-r--r-- 1 root root    0 Sep 15 17:44 rspec7.xml\r\n-rw-r--r-- 1 root root    0 Sep 15 17:44 rspec8.xml\r\n-rw-r--r-- 1 root root    0 Sep 15 17:44 rspec.xml\r\n```\r\n\r\nEverything within the mounted dir and above are owned by `apps`:\r\n\r\n```\r\ndrwxr-xr-x 17 apps apps  4096 Sep 16 06:00 .\r\ndrwxr-xr-x  9 apps apps  4096 Aug 24 15:24 ..\r\ndrwxr-xr-x 16 apps apps  4096 Aug 27 06:00 app\r\ndrwxr-xr-x  5 apps apps  4096 Sep 12 06:00 config\r\ndrwxr-xr-x  6 apps apps  4096 Sep  9 20:14 db\r\ndrwxr-xr-x  3 root root  4096 Sep 15 17:44 target\r\n```\r\n\r\nSince I am running as the host user `apps`, I wouldn't expect files to materialize as `root`.  What do I need to read to get a better understanding?"},"comment":{"url":"https://api.github.com/repos/docker/compose/issues/comments/140828959","html_url":"https://github.com/docker/compose/issues/2060#issuecomment-140828959","issue_url":"https://api.github.com/repos/docker/compose/issues/2060","id":140828959,"user":{"login":"dnephin","id":442180,"avatar_url":"https://avatars.githubusercontent.com/u/442180?v=3","gravatar_id":"","url":"https://api.github.com/users/dnephin","html_url":"https://github.com/dnephin","followers_url":"https://api.github.com/users/dnephin/followers","following_url":"https://api.github.com/users/dnephin/following{/other_user}","gists_url":"https://api.github.com/users/dnephin/gists{/gist_id}","starred_url":"https://api.github.com/users/dnephin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dnephin/subscriptions","organizations_url":"https://api.github.com/users/dnephin/orgs","repos_url":"https://api.github.com/users/dnephin/repos","events_url":"https://api.github.com/users/dnephin/events{/privacy}","received_events_url":"https://api.github.com/users/dnephin/received_events","type":"User","site_admin":false},"created_at":"2015-09-16T18:17:16Z","updated_at":"2015-09-16T18:17:16Z","body":"I'd say shared volumes is the recommended way.\r\n\r\nTo fix the permissions, you have to write the file as a non-root user. You need to create a user in the `Dockerfile` and then change to that user, either with `USER` in the dockerfile, `user:`  in the docker-compose.yml, or using `sudo -u <user>`"}}