Answer the question
In order to leave comments, you need to log in
Running services in docker container?
Hello everyone, I'm rolling my nginx + php image. I just started learning docker. I created my own docker image with nginx + php, registered all the configurations. I start the docker image with the command docker run -p 8080:80 -ti nginx-php-1 bash
, I start the nginx and php services there, I go through the host to 127.0.0.1:8080, the page with phpinfo is rendered, everything works.
Now, through the dockerfile, I want these services to start automatically and the container to run in the background. dockerfile
FROM nginx-php-1
MAINTAINER I am
CMD /etc/init.d/php7.2-fpm start && /etc/init.d/nginx start
Answer the question
In order to leave comments, you need to log in
Doing so is fundamentally wrong.
A Docker container is alive as long as the first process running in it is alive.
Theoretically, you can start several processes, but only from the first one. And when the first process is finished, the container will stop its work.
In order to start both services, you can use for example supervisor.
Run it as the first process, and nginx and fpm will already launch the supervisor itself and at the same time control their work.
More information about running multiple services in one container is written here:
https://docs.docker.com/config/containers/multi-se...
But there is an even more correct way - to run each service in a separate container.
To do this, dig towards docker-compose
IMHO the CMD format is not the same as that of RUN, adding two commands to it is problematic.
It is better to add a shell script to the container that will launch fpm and nginx, and write in CMD:
CMD [ "/etc/init.d/myscript" , "start"]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question