Docker creating root volume as owner

Asked

Viewed 414 times

1

I am trying to install the Laravel using the official image of the Composer, this is the command:

docker run -it --rm --user $(id -u):$(id -g) -v $(pwd)/src:/src composer create-project laravel/laravel /src

the problem is that it generates the /src folder with root permissions:

-rwxrwxrwx 1 igor igor 1926 mar 28 22:18 dc.sh
-rw-r--r-- 1 igor igor  192 mar 27 19:07 docker-compose.yml
-rw-r--r-- 1 igor igor 1906 mar 27 19:07 Dockerfile
drwxrwxrwx 3 igor igor 4096 mar 27 19:07 machine
-rw-r--r-- 1 igor igor   18 mar 27 19:07 README.md
drwxr-xr-x 2 root root 4096 mar 28 22:21 src

Note that I am already using --user $(id -u):$(id -g) to pick up the current user and pass it on to Docker, but nothing helps, anyone knows of any other method I can try?

1 answer

2

You must first create the folder that will be used as volume, in case src/:

mkdir src/

And then run the command normally:

docker run -it --rm -u $(id -u):$(id -g) -v $(pwd)/src:/src composer create-project laravel/laravel /src

You can also simplify the flag --user passing only -u, which also refers to the user.

This way, your user already has permission on the folder that will be used as volume, and the files that will be created inside it too, because Docker will take the current user and group, with the command -u $(id -u):$(id -g).

I took the test here and it worked correctly. :)

Dir

  • If I use -u it cannot use the cache inside the container because inside it is root :/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.