当我在Docker项目中运行Docker -compose up时,它失败了,并显示以下消息:

启动userland代理时错误:监听tcp 0.0.0.0:3000:绑定:地址已在使用

netstat -pna | grep 3000

显示了这个:

tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      -  

我已经试过docker-compose down了,但没用。


当前回答

首先,确定在特定端口中运行的是哪个服务。在您的示例中,您已经使用了端口号3000。

netstat -aof | findstr :3000

现在停止正在特定端口上运行的进程

lsof -i tcp:3000

其他回答

你可以用下面的命令杀死监听该端口的进程:

kill -9 $(lsof -t -i tcp:<port#>)

ex :

(lsof -t -i tcp:<port#>)

或者ubuntu:

Sudo lsof -t -i:8000 '

lsof的手册页:https://man7.org/linux/man-pages/man8/lsof.8.html

-9是硬杀,不检查任何deps。


(不相关,但可能有用,如果它的PORT 5000神秘)-罪魁祸首进程是由于Mac OS monterery。

端口5000通常用于为本地开发服务器提供服务。当更新到最新的macOS操作系统时,我无法将docker绑定到端口5000,因为它已经在使用中。(您可能会发现一条类似Port 5000已被使用的消息。)

通过运行lsof -i:5000,我发现使用端口的进程名为ControlCenter,这是一个原生macOS应用程序。如果这种情况发生在您身上,即使您使用暴力(并杀死)应用程序,它也会重新启动。在我的笔记本电脑中,lsof -i:5000返回控制中心正在被id为433的进程使用。我可以杀死所有-p 433,但macOS不断重新启动进程。

在这个端口上运行的进程原来是一个AirPlay服务器。你可以在

系统首选项›共享,取消检查AirPlay接收器以释放端口5000。

首先,确定在特定端口中运行的是哪个服务。在您的示例中,您已经使用了端口号3000。

netstat -aof | findstr :3000

现在停止正在特定端口上运行的进程

lsof -i tcp:3000

这帮助了我:

docker-compose down  # Stop container on current dir if there is a docker-compose.yml
docker rm -fv $(docker ps -aq)  # Remove all containers
sudo lsof -i -P -n | grep <port number>  # List who's using the port

然后: kill -9 <进程id> (macOS)或sudo kill <进程id> (Linux)。

来源:用户Rub21的评论。

让我再加一个例子,因为我有同样的错误,目前列出的解决方案都不可行:

serv1:
  ...
  networks:
  privnet:
    ipv4_address: 10.10.100.2
  ...

serv2:
  ...
  # no IP assignment, no dependencies
  
networks:
  privnet:
    ipam:
      driver: default
      config:
        - subnet: 10.10.100.0/24

根据init顺序,serv2可能会在serv1启动之前被分配IP 10.10.100.2,所以我只是手动为所有容器分配IP以避免错误。也许还有其他更优雅的方式。

更改docker更新的端口比关闭其他使用端口80的服务更有意义。