Docker volume files not writable, written as root

Viewed 3398

I own a folder, /me/tmp to which I mount a docker volume: docker run -v /me/tmp/:/root/tmp/. However when my Docker container creates folder and files instead the directory, e.g. /root/tmp/subdir/file.txt that file is created as root, and with no write permissions for other groups or users. This means that outside the container, I can't edit or even remove this file /me/tmp/subdir/file.txt. Is there any way to change the permissions or owner of the file without root access, or any way to avoid this from the start?

2 Answers

You could run docker with user mapping, so any file created with uid 0 (root in the container) is automatically mapped to another uid on the host. This is handled by two files /etc/subuid and /etc/subgid.

Read the official docs

Try running RUN chmod -R 777 /root/tmp/ or RUN chmod 777 /root/tmp/ in your dockerfile, or go into the container and type chmod -R 777 /root/tmp or chmod 777 /root/tmp as root. The -R is for recursive

Related