docker-compose exec composer as user
I have a docker-compose setup working perfect on my local machine for my symfony projects with nginx, php7-fpm and mysql.
I often need to install new packages via composer, so I just deliver the command to my php-fpm container like this:
docker-compose exec my-php-fpm-container composer install
The problem is that install all the packages as root, so I have to chown everytime I install something.
I know that the flag "--user" exist, but if I use it, it thows the following error:
ERROR: No such service: composer
Is there any way to run the docker-compose exec command as local machine user so the new composer installed files & folders create themselves with my local linux user ownership and not root?
Solution 1:
After doing some research I just realized that the php7-fpm image I am using has some users built-in like www-data (compatible with my actual box configuration). So I just had to use the flag "--user www-data" along with the command to use the composer inside the container and keep the files with the right permissions.
docker-compose exec --user www-data mycontainer composer install