I need to execute some commands from inside a php/php-7.1 container as a special (standard) user and group aka «www-data:www-data» used by php-fpm daemon.
www-data exists as both a user and a group on the host machine and entries exist in :
- /etc/passwd
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
- /etc/group
www-data:x:33:
Anyway, while the container is running, I firstly get the www-data uid and gid , as follows:
// con_php is the running container's name
echo $(docker exec -it con_php bash -c 'echo "$(id -u www-data)"''":"''"$(id -g www-data)"')
// outputs 33:33, great !
Then I use this (as a command line substitution) to feed the --user option supplied to the actual command I need to run inside the container. I now have:
docker exec \
--user $(docker exec -it con_php bash -c 'echo "$(id -u www-data)"''":"''"$(id -g www-data)"') \
con_php \
bash -c 'cd /var/www/project ; touch test.txt'
Unfortunately, when executed, Docker complains and outputs an error:
: no matching entries in group file
The following approach (a bash script with a temporary variable) leads to the same issue:
#! /bin/bash
usr=$(docker exec -it con_php bash -c 'echo "$(id -u www-data)"''":"''"$(id -g www-data)"')
echo "» $usr"
docker exec --user $usr con_php bash -c 'cd /var/www/project ; touch test.txt'
» 33:33
: no matching entries in group file
Thank you for your help.