0

I'm trying to create a docker image that runs Nginx and allows PHP pages to be loaded on a VM using php7.4-fpm. I'm able to start up my Nginx and it works with HTML pages but I can't find a way to start php7.4-fpm at the same time as Nginx. I want to be able to load PHP pages on this Nginx server. Is it possible to start several things at once in the ENTRYPOINT command? I am having a base layer of ubuntu:18.04 in my FROM and then installing both nginx and php7.4-fpm. Thanks.

ENTRYPOINT ["nginx", "-g", "daemon off;"] #Can I start php-fpm here as well??
Mully5474
  • 49
  • 3
  • https://stackoverflow.com/questions/54121031/multiple-commands-on-docker-entrypoint/54121254#54121254 – Truong Dang Aug 30 '21 at 02:16
  • I try all of these methods and my container exits immediately without actually running, I'm not sure why – Mully5474 Aug 30 '21 at 02:24
  • Did you try ` docker logs --details ` to see what happened? – Truong Dang Aug 30 '21 at 02:27
  • It won't come up with anything :(, not sure what the issue is – Mully5474 Aug 30 '21 at 02:51
  • 1
    You'll have a lot less trouble if you run one process in each container. I.e. a nginx container and a separate PHP container. Check out the examples under the 'php:-fpm' heading on this page https://hub.docker.com/_/php – Hans Kilian Aug 30 '21 at 06:19

1 Answers1

0

I assume you are doing this to learn how to write Dockerfiles. (If you actually just want to use it, I am pretty sure, you will find a container with nginx and php if you search for it. Also you should consider searching for one that is based on something like alpine, because the ubuntu container will consume a lot of resources.)

In cases like that, i usually use a start script inside the container, that contains my commands. I don't know which commands you, want but i created an example with just ping.

you can create a file called docker-entrypoint.sh in your working directory:

#!/usr/bin/env bash

ping localhost &
ping stackoverflow.com

the & at the end of the command has the effect, that it runs in the background and you can start other commands afterwards.

You should make sure, that your last command does not have that ampersand at the end and also it should be a blocking command, otherwise the container would exit, as soon as the last command is completed and all background commands will be stopped.

Inside the Dockerfile use

ENTRYPOINT [ "./docker-entrypoint.sh" ]
Woozar
  • 1,000
  • 2
  • 11
  • 35