Docker,Nginx和Supervisor nginx绑定失败

我正在尝试使用Nginx,Docker和Supervisor来安装服务器。

我面对的问题是,即使它工作,我可以看到index.html在我的浏览器,这个错误显示所有的时间: 2016/08/28 12:05:12 [emerg] 12#12: bind() to [::]:80 failed (98: Address in use) nginx: [emerg] bind() to [::]:80 failed (98: Address in use)

dockerfile:

 FROM nginx:stable-alpine RUN rm -f /etc/nginx/conf.d/* && mkdir -p /var/www/app COPY config/nginx.conf /etc/nginx/conf.d/ COPY config/supervisord.conf /supervisord.conf COPY scripts /scripts RUN chmod -R 700 /scripts CMD [ "/scripts/start" ] 

在/脚本/开始我有这个:

 #!/bin/bash supervisord -n -c /supervisord.conf 

然后在supervisord.conf中:

 [unix_http_server] file=/dev/shm/supervisor.sock ; (the path to the socket file) [supervisord] logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log) logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB) logfile_backups=10 ; (num of main logfile rotation backups;default 10) loglevel=info ; (log level;default info; others: debug,warn,trace) pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid) nodaemon=false ; (start in foreground if true;default false) minfds=1024 ; (min. avail startup file descriptors;default 1024) minprocs=200 ; (min. avail process descriptors;default 200) user=root ; [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [program:nginx] command=/usr/sbin/nginx autostart=true autorestart=true priority=10 stdout_events_enabled=true stderr_events_enabled=true stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 

而当我运行docker(没有守护进程的D选项),我得到了这个terminal输出:

 2016-08-28 12:05:10,474 CRIT Set uid to user 0 2016-08-28 12:05:10,481 INFO RPC interface 'supervisor' initialized 2016-08-28 12:05:10,481 CRIT Server 'unix_http_server' running without any HTTP authentication checking 2016-08-28 12:05:10,481 INFO supervisord started with pid 6 2016-08-28 12:05:11,484 INFO spawned: 'nginx' with pid 9 2016-08-28 12:05:11,497 INFO exited: nginx (exit status 0; not expected) 2016-08-28 12:05:12,499 INFO spawned: 'nginx' with pid 12 2016/08/28 12:05:12 [emerg] 12#12: bind() to 0.0.0.0:80 failed (98: Address in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address in use) 2016/08/28 12:05:12 [emerg] 12#12: bind() to [::]:80 failed (98: Address in use) nginx: [emerg] bind() to [::]:80 failed (98: Address in use) ........ 

看起来它产生了2个nginx进程,而不是一个进程,因为首先说它没有理由死掉,但实际上并没有死掉。

这里有很多问题。 通常情况下,除非你真的知道你在做什么,否则不build议在容器中运行supervisord。 此外,请确保您将supervisord中的nodaemon设置为true,否则docker将杀死您的容器,因为将不会有更多的pid 1(因为它将fork)。

nginx也一样。 Supervisord期望nginx不会分叉,而是保持在前台。 在nginxconfiguration文件中设置守护进程closures。