Docker 教程都绑定到端口 80,但在本地和远程服务器上失败,因为端口 80 已被使用

Docker tutorials all bind to port 80, and fail on local and remote servers as port 80 is already in use

我试图围绕所有这些 Docker 教程,但实际上没有解释端口 80 是什么。只是,"bind to port 80".

这是我在 运行 样本 Docker 文件:

之后遇到的第 3 个 Docker 教程,但出现了同样的错误

Error starting userland proxy: listen tcp 0.0.0.0:80: bind: address already in use

所以,我知道端口 80 基本上是默认端口,这将允许我的应用程序 运行 在 example.com 而不是 example.com:80 - 例如。我的 Web 服务器和本地计算机抱怨此端口正在使用中。当然可以,默认使用。

那么,为什么所有这些 Docker 教程都绑定到端口 80?我敢打赌他们做对了,我遗漏了一些东西……但是,找不到明确的解决方案或描述。

这是我正在做的教程:Digital Ocean 使用 Docker 安装 WordPress:https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-docker-compose

果然,端口 80 对我来说失败了:

webserver:
  depends_on:
    - wordpress
  image: nginx:1.15.12-alpine
  container_name: webserver
  restart: unless-stopped
  ports:
    - "80:80"
  volumes:
    - wordpress:/var/www/html
    - ./nginx-conf:/etc/nginx/conf.d
    - certbot-etc:/etc/letsencrypt
  networks:
    - app-network

将其更改为不会引发错误,但这意味着我们只能解析 http://example.com:90 -

ports:
  - "90:80"

我在这里错过了什么?为什么所有这些端口 80 的定义在我的 Mac 和远程 Digital Ocean Ubuntu8.1 服务器上都在本地失败?

你在端口 80 上还有其他东西 运行 吗?你可以试试 curl localhost:80 或者 lsof -i :80;你可能有 Apache 或其他东西 运行 默认情况下你需要杀掉它们。

example.com 和 example.com:80 是同一件事。在这里,您主机中的某些应用程序已经在监听端口 80,它与容器无关。可能,您也是主机中的 运行 一个 nginx 服务器。你是 ?

如果您像我一样使用 mac,sudo apachectl stop 帮我解决了这个问题。 Mac 有一个 built-in 网络服务器,我的默认是 运行。可能是由于 macbook pro 上的某些默认 websharing 功能。