在docker上将bind()绑定到0.0.0.0:80失败(98:地址已在使用中)

时间:2019-03-09 09:49:49

标签: docker nginx

启动容器后出现

2019/03/09 17:33:58 [emerg] 81#0: still could not bind()
2019/03/09 17:34:01 [emerg] 82#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2019/03/09 17:34:01 [emerg] 82#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2019/03/09 17:34:01 [emerg] 82#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2019/03/09 17:34:01 [emerg] 82#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
2019/03/09 17:34:01 [emerg] 82#0: bind() to 0.0.0.0:80 failed (98: Address already in use)

Dockerfile内容查看github地址

https://github.com/zhengxidong/docker/blob/master/lnp7.2_supervisord_dockerfile/Dockerfile

使用supervisord启动多个服务。Nginx配置文件配置daemon off;没有出现错误日志,这是为什么?如果删除了daemon off;,则没有上述错误。

2 个答案:

答案 0 :(得分:0)

您已经运行过两次nginx:

UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 01:27 pts/0    00:00:00 /usr/bin/python /usr/bin/supervisord
root         9     1  0 01:27 pts/0    00:00:00 /usr/sbin/sshd -D
root        10     1  0 01:27 pts/0    00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
root        11     1  0 01:27 pts/0    00:00:00 /usr/sbin/crond -n
root        12     1  0 01:27 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx <=============== Here
nginx       13    12  0 01:27 ?        00:00:00 nginx: worker process
nobody      14    10  0 01:27 pts/0    00:00:00 php-fpm: pool www
nobody      15    10  0 01:27 pts/0    00:00:00 php-fpm: pool www
root        68     0  0 01:29 pts/1    00:00:00 /bin/bash
root        84     1  0 01:29 pts/0    00:00:00 /usr/local/nginx/sbin/nginx <=== And Here
root        85    68  0 01:29 pts/1    00:00:00 ps -ef

第二个nginx运行失败,因为第一个已经运行。

N.B。

我建议您读the best practices来编写Dockerfile。您的图片将在10-15分钟内创建。

答案 1 :(得分:0)

这意味着nginx或其他进程已在使用端口80。

您可以使用以下方法杀死它:

sudo fuser -k 80/tcp

然后尝试重新启动nginx:

service nginx start

参考:https://easyengine.io/tutorials/nginx/troubleshooting/emerg-bind-failed-98-address-already-in-use