1

I'm trying to run as non root my php-fm ubuntu:20.04 but i can't.

Dockerfile

FROM ubuntu:20.04
ARG DEBIAN_FRONTEND noninteractive
ARG TZ=Europe/Paris

RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime && echo ${TZ} > /etc/timezone \
 && apt-get update \
 && apt-get -y install php-apcu \
    php-bz2 \
    php-cas \
    php-cli \
    php-curl \
    php-fpm \
    php-gd \
    php-imap \
    php-intl \
    php-json \
    php-ldap \
    php-mbstring \
    php-memcache \
    php-mysql \
    php-pear \
    php-pspell \
    php-tidy \
    php-xml \
    php-xmlrpc \
    php-xsl \
    php-zip \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

COPY www.conf /etc/php/7.4/fpm/pool.d/www.conf

CMD /etc/init.d/php7.4-fpm start \
&& bash

Do you know how to do this on ubuntu or on official docker php image ?

ckris L
  • 11
  • 2

1 Answers1

0

There are many similiar questions like this on SO already, this may help:

Switching users inside Docker image to a non-root user

The Dockerfile reference for the USER directive is also quite handy, and should get you going:

https://docs.docker.com/engine/reference/builder/#user

Edit:

From your responses, and further reading the Dockerfile, it seems like this is perhaps not quite the underlying issue you're trying to resolve

It's worth noting that php-fpm is a daemon and will not hold the container open if it dissapears to the background, I think you may have tried to mitigate this by adding && bash but bash will exit if it does not receive input.

It could be well worth using something like supervisord which allows you to define processes to start at the beginning of the container. It will also let you start a web server in your container that can talk nicely to fpm: How can I start php-fpm in a Docker container by default?

TheQueenIsDead
  • 865
  • 5
  • 19
  • Yes, but my user can't start the deamon php-fpm with CMD. I don't know which permission i can change. And with official php docker image is difficult to install the extension. – ckris L Aug 04 '21 at 03:55
  • It would be useful to explain what you did, and what behaviour you are seeing (`docker run` output, nothing at all, etc). Have you encountered the docker-php-ext-install utilities provided by the default php images? They could perhaps help with installing php extenstions: https://hub.docker.com/_/php I've added a small note about using supervisor to my original answer, perhaps it will help you in keeping the running process open, I'm afraid I had to guess at your issue since the current behavior isn't clear – TheQueenIsDead Aug 04 '21 at 20:52