Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker volume option create folder as "root" user

I am logged in in my PC (Fedora 24) as rperez. I have setup Docker for being able to run through this user, so I am running a container as follow:

$ docker run -d \
             -it \
             -e HOST_IP=192.168.1.66 \
             -e PHP_ERROR_REPORTING='E_ALL & ~E_STRICT' \
             -p 80:80 \
             -v ~/var/www:/var/www \
             --name php55-dev reypm/php55-dev

Notice the $ sign meaning I am running the command as a non root user (which uses #). The command above creates the following directory: /home/rperez/var/www but owner is set to root I believe this is because docker run as root user behind scenes.

Having this setup I am not able to create a file under ~/var/www as rperez because the owner is root so ...

What is the right way to deal with this? I have read this and this but is not so helpful.

Any help?

like image 895
ReynierPM Avatar asked Sep 30 '16 15:09

ReynierPM


2 Answers

As discussioned here, this is an expected behavior of docker. You can create the target volume directory before running docker command or change the owner to your current user after the directory is created by docker:

chown $(whoami) -R /path/to/your/dir
like image 147
Kane Blueriver Avatar answered Oct 08 '22 08:10

Kane Blueriver


I hit this same issue (also in a genomics context for the very same reason) and also found it quite unintuitive. What is the recommended way to "inherit ownership". Sorry if this described elsewhere, but I couldn't find it. Is it something like:

docker run ... -u $(id -u):$(id -g) ...
like image 41
Razzwan Avatar answered Oct 08 '22 09:10

Razzwan