Docker Error bind: address already in use

2020-02-16 08:44发布

When I run docker-compose up in my Docker project it failes with the following message:

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

netstat -pna | grep 3000 shows this:

tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      -  

I've already tried docker-compose down, but it doesn't help.

12条回答
Bombasti
2楼-- · 2020-02-16 08:46

This helped me:

docker-compose down
docker rm -fv $(docker ps -aq)
sudo lsof -i -P -n | grep <port number>

and then: kill -9 <process id> (macOS) or sudo kill <process id> (Linux).

Source: comment by user Rub21.

查看更多
Animai°情兽
3楼-- · 2020-02-16 08:46

I had the same problem. I fixed this by stopping the Apache2 service on my host.

查看更多
成全新的幸福
4楼-- · 2020-02-16 08:46

In my case it was

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

And all that I need is turn off debug listening in php storm icon

查看更多
太酷不给撩
5楼-- · 2020-02-16 08:49

In your case it was some other process that was using the port and as indicated in the comments, sudo netstat -pna | grep 3000 helped you in solving the problem.

While in other cases (I myself encountered it many times) it mostly is the same container running at some other instance. In that case docker ps was very helpful as often I left the same containers running in other directories and then tried running again at other places, where same container names were used.

How docker ps helped me: docker rm -f $(docker ps -aq) is a short command which I use to remove all containers.

Edit: Added how docker ps helped me.

查看更多
爷、活的狠高调
6楼-- · 2020-02-16 08:50

Check docker-compose.yml, it might be the case that the port is specified twice.

version: '3'
services:
  registry:
    image: mysql:5.7
        ports:
      - "3306:3306"             <--- remove either this line or next
      - "127.0.0.1:3306:3306"
查看更多
不美不萌又怎样
7楼-- · 2020-02-16 08:51
docker-compose down --rmi all 

and then restart your computer

查看更多
登录 后发表回答