There is such a Dockerfile :

FROM zercle/docker-ubuntu # Update OS RUN apt update && apt -y full-upgrade # Install PHP RUN apt-add-repository -y ppa:ondrej/php \ && apt update \ && apt -y install \ php-ssh2 \ php7.1-cli \ php7.1-curl \ php7.1-fpm \ php7.1-gd \ php7.1-gmp \ php7.1-imap \ php7.1-json \ php7.1-ldap \ php7.1-mbstring \ php7.1-mcrypt \ php7.1-mysql \ php7.1-opcache \ php7.1-pgsql \ php7.1-readline \ php7.1-snmp\ php7.1-soap \ php7.1-sqlite3 \ php7.1-xml \ php7.1-xmlrpc \ php7.1-xsl \ php7.1-zip \ php-memcached \ php-mysqlnd-ms \ php-imagick RUN apt-get install -y nginx RUN systemctl enable php7.1-fpm.service RUN service nginx start RUN service php7.1-fpm start # Clean file RUN apt-get autoclean EXPOSE 9000 #ENTRYPOINT ["/etc/init.d/nginx", "restart", ";", "/etc/init.d/php7.1-fpm", "restart"] #CMD /etc/init.d/php7.1-fpm restart && /etc/init.d/nginx restart #CMD service php7.1-fpm start CMD /etc/init.d/nginx restart #CMD ["/etc/init.d/nginx", "restart", "&&", "/etc/init.d/php7.1-fpm", "restart"] 

So the point is that nginx & php-fpm does not start when $ docker-compose up -d .

Everything is working, because if you run nginx & php-fpm from under the container, everything works fine.

The next question is - how can I “automatically” raise the necessary services inside the docker-container?

    2 answers 2

    Docker means only one process as a starting point for a container while you are trying to start several. This does not mean that it is impossible to start several processes in a container; it is just that a container is born from one process and dies with it. This is not very different from the operating system, which has exactly the same source process (init), which runs all the others.

    Therefore, ENTRYPOINT and CMD are all components of a single process: being concatenated, they are an array of strings, the first of which indicates the binary being started, and all the rest are launch arguments. Therefore, de facto ";" and "&&" are nothing more than strings passed to the script. They have a separate meaning only in the shell, the command execution environment, the docker operates with processes, and he has no such concepts.

    Therefore, if you want to run several processes in a container, you need a parent script / binary that runs them and lives until both of them run out - or, on the contrary, ask them to finish when the completion signal is sent to it. The easiest way to do this is with an arbitrary supervisor (eg supervisord), but this goes against the docker's philosophy. Docker proposes [including] replacing virtual machines with one another; however, thanks to the shared core, docker containers consume almost nothing beyond the processes wrapped in them, and according to the docker concept, divide one container into two (nginx, php-fpm) and run them separately, communicating over the network.

       RUN systemctl enable php7.1-fpm.service RUN service nginx start RUN service php7.1-fpm start 

      This is superfluous, since

      • systemd does not work at all (does not make sense) in Docker
      • calling start will start the process only at build time.

      RUN apt-get autoclean

      This call also makes no sense, since

      • Docker itself cleans the apt cache in the same layer where the installation was
      • all unnecessary files were already fixed in the layer (if Docker had not cleaned up) where the installation was, this command will only increase the space occupied, as it will add the entries "consider this file to be deleted"

      If it is important to put php-fpm and nginx in one container, see how it is done in the phpMyAdmin container

      But I would recommend taking the official php image with Apache https://hub.docker.com/_/php/ and supplement it, for example

       FROM php:apache RUN a2enmod rewrite \ && docker-php-ext-install mysqli 

      Or, if this is not acceptable, run two containers: nginx separately and php:fpm separately.