Search code examples
linuxdockerdocker-volumedocker-container

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?


Solution

  • 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