7

I am using the official php:alpine https://github.com/docker-library/php/blob/master/7.2/alpine3.7/fpm/Dockerfile as my base image. My projects are basically composer based project. So I installed composer on it like below.

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin -- --filename=composer

When I install any packages using composer install it runs as root as the main php process runs as root. So how can I run main php process as root and composer as another non root user deploy?

Update-1 My dockerfile is like below. So as you can see I am not installing composer packages inside dockerfile rather I install those packages on container like docker exec -it php composer install.

FROM php:7.2-fpm-alpine
..........................
..........................
..........................
RUN  set ex \
  # Install Composer( Requires git )
  && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin -- --filename=composer \
  ENTRYPOINT ["/entrypoint.sh"]
  CMD ["php-fpm"]

I was trying to achieve it like https://unix.stackexchange.com/questions/476155/how-to-pass-multiple-parameters-to-su-user-c-command but in vain.

SkyRar
  • 1,107
  • 1
  • 20
  • 37

1 Answers1

5

Incase anyone wants to achieve the same follow instructions below

I added a USER in dockerfile so that composer will be run as user deploy in future. But php-fpm needs to be run as root. So I set a setuid bit on the php-fpm binary. And now everything got resolved.

RUN chmod u+s /usr/sbin/php-fpm7

USER deploy
ENTRYPOINT ["/entrypoint.sh"]
CMD ["php-fpm7","-F"]
SkyRar
  • 1,107
  • 1
  • 20
  • 37
  • be care php-fpm run as the user defined in php-fpm.conf if you run it as root, if you run it as another user like here, it will not be root. – severin.julien Aug 27 '20 at 08:55