解決:ERROR: for nginx  Cannot start service nginx: Ports are not available: listen tcp 0.0.0.0:80

一、問題場景

在 Mac 上的 docker 配置項目下執行以下命令:

docker-compose up

提示以下錯誤:

ERROR: for nginx  Cannot start service nginx: Ports are not available: 
listen tcp 0.0.0.0:80: bind: address already in use

二、問題原因

通過以上錯誤提示發現 80 端口已經被佔用,看一下被誰佔用了:

bash-3.2# lsof -i :80

COMMAND  PID       USER   FD   TYPE         DEVICE SIZE/OFF NODE NAME
httpd    117       root    4u  IPv6 0x56      0t0  TCP *:http (LISTEN)
httpd    371       _www    4u  IPv6 0x56      0t0  TCP *:http (LISTEN)
httpd   2452       _www    4u  IPv6 0x56      0t0  TCP *:http (LISTEN)
httpd   2455       _www    4u  IPv6 0x56      0t0  TCP *:http (LISTEN)
httpd   2456       _www    4u  IPv6 0x56      0t0  TCP *:http (LISTEN)
httpd   5443       _www    4u  IPv6 0x56      0t0  TCP *:http (LISTEN)

發現是 Apache 佔用了 80 端口。

我的系統是:MacOS Catalina 10.15.4(不確定是不是升級新系統的原因),開機後會自動啓動 Apacha,這個會自動佔用 80 端口,如果想啓動 Nginx 監聽 80 端口,必須停掉 Apacha。

三、解決方案

使用以下命令可以停掉 Apacha:

sudo apachectl stop

停掉之後再執行以下命令就沒什麼問題了:

docker-compose up

搞定!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章