Reputation: 39
My jenkins starts 'php' docker container by jenkins user. Inside container any created file has owner root, like 'composer install' will create 'vendor' directory with root owner. So jenkins can't cleanup workspace.
A was add to Dockerfile
RUN useradd -r jenkins
USER jenkins
but container can't start. Logs tell me:
NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root
ERROR: Unable to create the PID file (/run/php-fpm.pid).: Permission denied (13)
ERROR: FPM initialization failed
Than, i was tried run inside container
chown jenkins:jenkins * -R
But after build finished, i was get unknown owner for my files:
drwxr-xr-x 3 libstoragemgmt input
drwxr-xr-x 6 libstoragemgmt input
User 'libstoragemgmt' with group 'input'
Upvotes: 0
Views: 884
Reputation: 41950
Perhaps the method explained here would work for you. https://jtreminio.com/blog/running-docker-containers-as-current-host-user/
It involves deleting the internal www-data
user and recreating it with the same ID as the host user. In your case that would be the jenkins
user ID.
This is the example from the article:
FROM jtreminio/php:7.2
ARG USER_ID=1000
ARG GROUP_ID=1000
RUN userdel -f www-data &&\
if getent group www-data ; then groupdel www-data; fi &&\
groupadd -g ${GROUP_ID} www-data &&\
useradd -l -u ${USER_ID} -g www-data www-data &&\
install -d -m 0755 -o www-data -g www-data /home/www-data &&\
chown --changes --silent --no-dereference --recursive \
--from=33:33 ${USER_ID}:${GROUP_ID} \
/home/www-data \
/.composer \
/var/run/php-fpm \
/var/lib/php/sessions
USER www-data
Upvotes: 1