当我在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了,但没用。


当前回答

改变network_mode:“bridge”到“host”。

这与

version: '2.2'
services:
  bind:
    image: sameersbn/bind:latest
    dns: 127.0.0.1
    ports:
      - 172.17.42.1:53:53/udp
      - 172.17.42.1:10000:10000
    volumes:
        - "/srv/docker/bind:/data"
    environment:
      - 'ROOT_PASSWORD=secret'
    network_mode: "host"

其他回答

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

netstat -aof | findstr :3000

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

lsof -i tcp:3000

检查docker-compose。Yml,可能会出现端口被指定两次的情况。

version: '3'
services:
  registry:
    image: mysql:5.7
        ports:
      - "3306:3306"             <--- remove either this line or next
      - "127.0.0.1:3306:3306"

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

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。

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

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以避免错误。也许还有其他更优雅的方式。

使用8888端口的是Jupiter,我必须更改Jupiter笔记本的配置文件以在另一个端口上运行。

列出谁在使用该特定端口。 9 . sudo lsof -i -P -n | grep

你可以在~/.jupyter/jupyter_notebook_config.py中指定你想要Jupyter运行的端口,不注释/编辑下面的行:

c.NotebookApp.port = 9999

如果你没有jupyter_notebook_config.py,试着运行jupyter notebook——generate-config。有关Jupyter配置的更多详细信息,请参见此。