[ubuntu] Docker Error bind: address already in use

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.

This question is related to ubuntu docker ubuntu-14.04 bind docker-compose

The answer is


I upgraded my docker this afternoon and ran into the same problem. I tried restarting docker but no luck.

Finally, I had to restart my computer and it worked. Definitely a bug.


Just a side note if you have the same issue and is with Windows:

In my case the process in my way is just grafana-server.exe. Because I first downloaded the binary version and double click the executable, and it now starts as a service by user SYSTEM which I cannot taskkill (no permission)

I have to go to "Service manager" of Windows and search for service "Grafana", and stop it. After that port 3000 is no longer occupied.

Hope that helps.


Changing network_mode: "bridge" to "host" did it for me.

This with

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"

`$` sudo service redis-server stop

Does the trick.


I ran into the same issue several times. Restarting docker seems to do the trick


The one that was using the port 8888 was Jupiter and I had to change the configuration file of Jupiter notebook to run on another port.

to list who is using that specific port. sudo lsof -i -P -n | grep 9

You can specify the port you want Jupyter to run uncommenting/editing the following line in ~/.jupyter/jupyter_notebook_config.py:

c.NotebookApp.port = 9999

In case you don't have a jupyter_notebook_config.py try running jupyter notebook --generate-config. See this for further details on Jupyter configuration.


In some cases it is critical to perform a more in-depth debugging to the problem before stopping a container or killing a process.

Consider following the checklist below:

1) Check you current docker compose environment
Run docker-compose ps.
If port is in use by another container, stop it with docker-compose stop <service-name-in-compose-file> or remove it by replacing stop with rm.

2) Check the containers running outside your current workspace
Run docker ps to see list of all containers running under your host.
If you find the port is in use by another container, you can stop it with docker stop <container-id>.
(*) Because you're not under the scope of the origin compose environment - it is a good practice first to use docker inspect to gather more information about the container that you're about to stop.

3) Check if port is used by other processes running on the host
For example if the port is 6379 run:

$ sudo netstat -ltnp | grep ':6379'
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      915/redis-server 12 
tcp6       0      0 ::1:6379                :::*                    LISTEN      915/redis-server 12

(*) You can also use the lsof command which is mainly used to retrieve information about files that are opened by various processes (I suggest running netstat before that).

So, In case of the output above the PID is 915. Now you can run:

$ ps j 915
 PPID   PID  PGID   SID TTY      TPGID STAT   UID   TIME COMMAND
    1   915   915   915 ?           -1 Ssl    123   0:11 /usr/bin/redis-server 127.0.0.1:6379

And see the ID of the parent process (PPID) and the execution command.
You can also run: $ pstree -s <PID> to a visual display of the process and its related processes.

In our case we can see that the process probably is a daemon (PPID is 1) - In that case consider running:
A) $ cat /proc/<PID>/status in order to get a more in-depth information about the process like the number of threads spawned by the process, its capabilities, etc'.
B) $ systemctl status <PID> in order to see the unit that caused the creation of a specific process. If the service is not critical - you can stop and disable the service.

4) Restart Docker service
Run: sudo service docker restart.

5) You reached this point and..
Only if its not placing your system at risk - consider restarting the server.


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"

This helped me:

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

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

Source: comment by user Rub21.


On my machine a PID was not being shown from this command netstat -tulpn for the in-use port (8080), so i could not kill it, killing the containers and restarting the computer did not work. So service docker restart command restarted docker for me (ubuntu) and the port was no longer in use and i am a happy chap and off to lunch.


I resolve the issue by restarting Docker.


maybe it is too rude, but works for me. restart docker service itself

sudo service docker restart

hope it works for you also!


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


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


I had same problem, docker-compose down --rmi all (in the same directory where you run docker-compose up) helps

UPD: CAUTION - this will also delete the local docker images you've pulled (from comment)


Before it was running on :docker run -d --name oracle -p 1521:1521 -p 5500:5500 qa/oracle I just changed the port to docker run -d --name oracle -p 1522:1522 -p 5500:5500 qa/oracle

it worked fine for me !


docker-compose down --rmi all 

and then restart your computer


I was getting the below error when i was trying to launch a new conatier- listen tcp 0.0.0.0:8080: bind: address already in use.

Solution: netstat -tulnp | grep 8080

[[email protected] (aws_main) ~]# netstat -tulnp | grep 8080 tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 12749/java [[email protected] (aws_main) ~]#

kill -9 12749

Then try to relaunch the container it should work


A variation of @DmitrySandalov's answer: I had tomcat/java running on 8080, which needed to keep going. Looked at the docker-compose.yml file and altered the entry for 8080 to another of my choosing.

nginx:
  build: nginx
  ports:
    #- '8080:80' <-- original entry
    - '8880:80'
    - '8443:443'

Worked perfectly. (The only wrinkle is the change will be wiped if I ever update the project, since it's coming from an external repo.)


For Linux/Unix:

Simple search for linux utility using following command

netstat -nlp | grep 8888

It'll show processing running at this port, then kill that process using PID (look for a PID in row) of that process.

kill PID

Examples related to ubuntu

grep's at sign caught as whitespace "E: Unable to locate package python-pip" on Ubuntu 18.04 How to Install pip for python 3.7 on Ubuntu 18? "Repository does not have a release file" error ping: google.com: Temporary failure in name resolution How to install JDK 11 under Ubuntu? How to upgrade Python version to 3.7? Issue in installing php7.2-mcrypt Install Qt on Ubuntu Failed to start mongod.service: Unit mongod.service not found

Examples related to docker

standard_init_linux.go:190: exec user process caused "no such file or directory" - Docker What is the point of WORKDIR on Dockerfile? E: gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of them is required for this operation How do I add a user when I'm using Alpine as a base image? docker: Error response from daemon: Get https://registry-1.docker.io/v2/: Service Unavailable. IN DOCKER , MAC How to fix docker: Got permission denied issue pull access denied repository does not exist or may require docker login Docker error: invalid reference format: repository name must be lowercase Docker: "no matching manifest for windows/amd64 in the manifest list entries" OCI runtime exec failed: exec failed: (...) executable file not found in $PATH": unknown

Examples related to ubuntu-14.04

Yarn install command error No such file or directory: 'install' How to remove docker completely from ubuntu 14.04 Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running? Docker Error bind: address already in use no target device found android studio 2.1.1 How to use systemctl in Ubuntu 14.04 Android Studio: /dev/kvm device permission denied How to download a folder from github? Ubuntu: Using curl to download an image Compile c++14-code with g++

Examples related to bind

Docker Error bind: address already in use Update Angular model after setting input value with jQuery How to remove an appended element with Jquery and why bind or live is causing elements to repeat How to enable named/bind/DNS full logging? What does it mean to bind a multicast (UDP) socket? Detect user scroll down or scroll up in jQuery Cannot assign requested address using ServerSocket.socketBind jQuery bind/unbind 'scroll' event on $(window) What is the use of the JavaScript 'bind' method? Understanding ASP.NET Eval() and Bind()

Examples related to docker-compose

E: gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of them is required for this operation How to upgrade docker-compose to latest version How to fix docker: Got permission denied issue Docker error: invalid reference format: repository name must be lowercase Is it safe to clean docker/overlay2/ Docker: How to delete all local Docker images Docker "ERROR: could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network" How to run docker-compose up -d at system start up? How to create a DB for MongoDB container on start up? How to use local docker images with Minikube?