Every time I create a new container, I have to enter the container and start nginx and php. How can I make nginx and php start automatically every time I create a new container?
淡淡烟草味2017-05-16 13:01:56
You can use supervisord to manage
First enter the container to install supervisord, (search online for the installation process)
It is recommended to place the main configuration file in: /etc/supervisord.conf vim /etc/supervisord.conf
[unix_http_server]
file=/var/run/supervisor.sock
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisord]
nodaemon=true
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock
[include]
files = /etc/supervisor/conf.d/*.conf
Then add the startup commands for php and nginx in /etc/supervisor/conf.d/
For example, add nginx, vim /etc/supervisor/conf.d/nginx_super.conf
[program:nginx]
command=nginx
Then submit a new image, for example
docker commit -a "qclaogui" -m "bulabula" nginx-php:commit
Write a new Dokcerfile
FROM nginx-php:commit
MAINTAINER xxx@xxx.com
EXPOSE 80 443
ENTRYPOINT ["/usr/bin/supervisord","-c","/etc/supervisord.conf"]
Rebuild an image
docker build -t nginx-php:v1 .
Run the container based on the newly built image
docker run --name test-nginx-php -p 8081:80 -d nginx-php:v1
注意这里用的是-d
Parameters
Depending on your situation, the general solution is as follows, you can refer to it