我想在Docker中运行一个Laravel应用程序,但是在第一步就失败了。我尝试使用docker/getting started 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.
这里列出了正在运行的内容:
$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的进程,因此我已经将它们杀死(除了错误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
(希望能对其他人有所帮助)。这提供了
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重新启动,我认为我不需要它们,但它们是否与系统有关?我如何完全终止它们,并且它们是否实际上阻止我使用Docker的80端口?
sudo: stop: command not found
。端口8080也遇到了同样的问题,我认为这是因为我正在运行Laravel Valet,它使用nginx。 - Jeremysudo brew services stop nginx
或者sudo nginx -s stop
命令来停止它。参考链接:https://serverfault.com/questions/141975/how-to-stop-nginx-on-mac-os-x - invad0r$valet stop
命令,我认为这解决了问题。现在运行lsof -n -i4TCP:80 | grep LISTEN
不再返回任何内容,并且运行 Docker 命令已经设置了一个容器。我将标记为已解决。谢谢。 - Jeremy