解封80端口/nginx/docker

Unblocking port 80 / nginx / docker

我想在 Docker 中获得一个 Laravel 应用程序 运行ning,但我在第一个障碍上失败了,我尝试使用 docker/getting 启动 Docker 使用以下命令生成图像,但出现以下阻塞情况。

$docker run -p 80:80 docker/getting-started

docker: Error response from daemon: Ports are not available: listen tcp 0.0.0.0:80: bind: address already in use.

在这里列出什么是 运行ning:

$sudo lsof -i :80

COMMAND   PID          USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
nginx     143          root    6u  IPv4 0x17106caf335097c7      0t0  TCP localhost:http (LISTEN)
nginx   10145 Jeremyrrsmith    6u  IPv4 0x17106caf335097c7      0t0  TCP localhost:http (LISTEN)
nginx   10218 Jeremyrrsmith    6u  IPv4 0x17106caf335097c7      0t0  TCP localhost:http (LISTEN)
nginx   10296 Jeremyrrsmith    6u  IPv4 0x17106caf335097c7      0t0  TCP localhost:http (LISTEN)
nginx   10372 Jeremyrrsmith    6u  IPv4 0x17106caf335097c7      0t0  TCP localhost:http (LISTEN)

根据我的阅读,我需要杀死端口 80 上 运行ning 的所有内容,所以已经杀死了它们(143 错误除外),但它们以新的 PID 重新启动。我真的应该杀死这些吗?

Docker: Error response from daemon: Ports are not available: listen tcp 0.0.0.0:80: bind: address already in use. 错误让我很头疼。

根据其他线程,

netstat -ltnp | grep 80 是对 运行 的常见命令,但我得到 netstat: option requires an argument -- p 作为响应。读到后,第一个是 Linux 命令(在其他线程中我不清楚)。我在 Mac。 lsof -n -i4TCP:80 | grep LISTEN 是 mac 上的命令(希望对其他人有帮助)。这提供了

nginx   10145 Jeremyrrsmith    6u  IPv4 0x17106caf335097c7      0t0  TCP 127.0.0.1:http (LISTEN)
nginx   10218 Jeremyrrsmith    6u  IPv4 0x17106caf335097c7      0t0  TCP 127.0.0.1:http (LISTEN)
nginx   10296 Jeremyrrsmith    6u  IPv4 0x17106caf335097c7      0t0  TCP 127.0.0.1:http (LISTEN)
nginx   10372 Jeremyrrsmith    6u  IPv4 0x17106caf335097c7      0t0  TCP 127.0.0.1:http (LISTEN)

我杀掉了这些 PID,它们只是用一个新的 PID 重新启动,我认为我不需要它们,但它们与系统相关吗?我该如何永远杀死它们,它们是否真的阻止我将端口 80 用于 Docker?

您的设备上安装了 nginx 运行,它阻塞了端口 80,就像您自己说的那样。

你自己安装过nginx吗? 它是否作为系统服务安装,在您打开设备时自动启动?

如果它作为系统服务运行,您可能需要使用适当的系统命令逐渐关闭它,而不是试图终止进程。我不知道Mac上的这个命令是什么,但是你搜索一下就会发现。

在 linux 上,这取决于您的系统,例如是 systemctl stop nginx.

你知道nginx进程是从哪里来的吗?

绕过已用端口的最简单和最常见的方法是使用不同的端口映射,例如 docker run -p 8080:80 docker/getting-started 并通过 localhost:8080

访问

如果您想使用端口 80,您可能必须停止 nginx 服务而不是终止进程。

我认为是 laravel 代客。我只有 $valet stop,我认为它已经解决了。作为 lsof -n -i4TCP:80 | grep LISTEN now returns nothing and 运行 docker 命令已经设置了一个容器。所以80端口被laravel代客添加的nginx阻塞了,要使用80端口你需要停止代客,当你不再需要这个端口时重新启动它。我觉得。