首页 > 解决方案 > 在 docker 上绑定()到 0.0.0.0:80 失败(98:地址已在使用中)

问题描述

启动容器后出现

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;,没有上面的错误。

标签: dockernginx

解决方案


你已经运行了 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 无法运行,因为第一个已经运行。

注意

我建议您阅读编写 Dockerfile的最佳实践。您的图像在 10-15 分钟内创建。


推荐阅读