210

I am trying to run a docker example following this documentation

This is my command:

docker run -d -p 80:80 --name webserver nginx

But I get this error:

docker: Error response from daemon: driver failed programming external connectivity on endpoint webserver (bd57efb73c738e3b271db180ffbee0a56cae86c8193242fbc02ea805101df21e): Error starting userland proxy: Bind for 0.0.0.0:80: unexpected error (Failure EADDRINUSE).

How do I fix this?

20 Answers 20

146

From your error message, the EADDRINUSE indicates port 80 is already in use on either the docker VM or possibly directly on your laptop. You can either stop whatever is running on that port, or change the port used in your Docker, command. To change to the external port 8080, use:

docker run -d -p 8080:80 --name webserver nginx
Sign up to request clarification or add additional context in comments.

4 Comments

In my case it didn't explicitly mention the port which had issue, but since i was exposing a series of ports (-p 1000-2000:1000-2000) I doubted this would be the reason
restart docker service - is fastest step so it should be tested first
@IlyaKolesnikov yes, just like a hammer is the fastest way to install a drywall screw. I'd still want to check what is using the port, and if stopping docker fixed it, then it was a container listening on the port, and stopping the one container would solve it without killing everything else. Use docker ps to see what containers are running/listening on ports.
@shabby with the range you don't listen on any port in the range, you listen on every port in the range, at least from docker setting up the forwarder from the host to container.
128

If you are the port i not in use, try restarting docker. That usually works for me. On Windows:

enter image description here

Depending on your Linux distro, you can restart Docker with this command:

sudo systemctl restart docker

7 Comments

This is the best place to start, especially if it's a port that you're reasonably sure isn't in use.
Sometimes restarting the computer also helps.
In your cases probably a docker system prune --volumes might also help without a restart of the service. – !!! BEWARE !!!: it will remove lot of stuff, so first check your containers with docker ps -a & docker images -a, to ensure you aren't gonna loose something important (aka not recoverable). This prune will free up space from the limited size disk residing on the VM (with Docker Desktop for Windows, or macOS). That is often a reason for Docker Desktop to start having highly unpredictable behaviours.
Why are you suggesting this at all?
You can get process ID of the port running on your docker by running this command- sudo lsof -i tcp:<PORT NUMBER> Then once you have Process Id and you can kill it with - kill -9 <PID> Now your processes running on your port will be shut down and you can again start docker and it will work fine then.
Ugh this finally fixed the issue for me, didn't know you could restart through UI like that
|
67

I had the same issue with one of my containers. I tried everything but when nothing worked, I tried the following and launched the container again with success

sudo service docker stop
sudo rm /var/lib/docker/network/files/local-kv.db
sudo service docker start

5 Comments

In Windows you will find this file in C:\ProgramData\Docker\network\files
Do sudo docker system prune if you get network not found after running above commands. and then docker-compose up should run fine.
This just saved me :) Awesome... I tried everything, deleted process with ports, removed cache etc bit nothing was working... You are saviour
It works well on Ubuntu OS. Thanks for sharing the code.
But then you loose all your networks
61

Try restarting the docker service. It works 99% of the time.

service docker restart

If that didn't work as expected, try restarting your pc and then restarting the docker service using above command.

If none of the above worked try changing the exposed port to another unused port that should work.

docker run -d -p 81:80 --name webserver nginx

Note :- 81 is the port on your host and 80 is the port on your docker container

4 Comments

Last thing worked. I changed the ports in the docker-compose file from 3306:3306 to 3307:3307, then the error ERROR: for MYDOCKERCOMPOSESERVICE Cannot start service MYDOCKERCOMPOSESERVICE: driver failed programming external connectivity on endpoint MYDOCKERCOMPOSESERVICE vanished.
But it will not solve your business use case. By using in your method you are not actually exposing your application to external word. try with 3307:3306 since your service inside docker runs in 3306. You can access it via 3307 from host machine.
The docker-compose ran through after this change to 3307:3307. This is because port 3306 was already in use by a local mysql container that blocked this port. I tried 3307:3306 and it also worked, yes, thanks.
systemctl restart docker
24

You can try the following steps to resolve the problem and also able to understand the reason why you had faced the problem in details:

Step-1: check all the running containers using the command:

docker ps

Step-2: Find out the container id of the container which is running on the same port, you are trying to reach.

enter image description here

Step-3: Stop the container which one is running on the same port using this command:

docker stop <container id> 

Step-4: Again build the container:

docker build -t DockerID/projectName .

Step-5: Again try to run your container on the same port using port mapping.

docker run -p 8080:8080 DockerID/projectName

Comments

21

Try this command:

sudo service docker restart

If it does not help, restart your server.

Comments

14

Stop all the running containers docker ps -a -q then Stop the Docker on your machine & restart it.

1 Comment

This worked for me. I had the same issue for a container that used to run fine. This happened after modifying firewall settings. The whole error message had an 'iptables failed' in it. After reading smishra's comment I decided to just start and stop (=restart) docker, without removing the file mentioned there, and that worked for me. I then read your comment and realized that that basically what I did.
11

Recently this problem started to happen a lot on Windows. You can try restarting docker or you can manually stop docker before Windows shutdown - docker starts cleanly on reboot. On 7/24/2018 docker issue is open and further details can be found at https://github.com/docker/for-win/issues/1967

Comments

11

Check what's on port 80 right now - sudo ss -tulpn | grep :80

You may have apache2 running. You can check it - sudo service apache2 status If so - sudo service apache2 statop

1 Comment

This would've worked for me but what I ended up doing was removing a port forwarding rule with the port in question on one of my VirtualBox guests.
8

If you tried all above solutions and still having issues, you can kill LISTEN ports manually as below for Linux users

  1. sudo lsof -i -P -n | grep LISTEN enter image description here
  2. sudo kill -9 <process_pid> (ex. sudo kill -9 28563 28575 28719 28804)

Comments

3

I had same problem with same error. As long as I had a local nginx installed in my computer, running another nginx through the container made conflict in port :80. Simply I tried to stop the service of my local installed nginx as below:

sudo service nginx stop

Then after, I could run nginx by docker-compose up -d without any problem:

Creating MyWebServer ... done
Creating mongo    ... done
Creating redis    ... done

Comments

2

In my case, port 80 is the default port for the web server and therefore it is protected. I changed the bind to port 60:8080 to ensure no deeper issues. Changing the bind to a different port allows me to execute the docker run and hit it in the browser at http://ip:60

Comments

2

If this case is with Redis: remove the ports - ... in the docker-compose file and let it assign by itself. or change the port mapping in the host from 6379:6379 to 6378:6379 that worked for me.

2 Comments

I had the same issue when setting up Airflow with docker-compose - I had to change all of the HOST ports (just decreased them by one digit)
Same issue at my end. so changed as suggested worked.
2

If you are using WSL, after i tried all above and still it doesn't work, i tried to restart the WSL from Powershell with admin privileges and shutdown command:

wsl --shutdown

That worked for me.

Comments

2

You can kill all the processes associated with port 8000 by running the following command.

sudo fuser -k 8000/tcp

Then run the command that you were running initially.

Comments

1

windows users: docker description

On Windows systems, CTRL+C does not stop the container. So, first type CTRL+C to get the prompt back (or open another shell), then type docker container ls to list the running containers, followed by docker container stop to stop the container. Otherwise, you get an error response from the daemon when you try to re-run the container in the next step.

I had the same problem, I thought with CTRL+C stoped the container but it was not the case, any af the answer above works because they all stop containers, restarting docker or stoping container explicity.

I prefer:

docker container ls #list containers running
docker stop [container id] #replace [container id] with the container id running

Comments

1

This seems to be an incompatibility problem with windows "fast-boot" as described here: (just restart the docker service) and it may work.

https://github.com/docker/for-win/issues/2722

This is caused by an incompatibility with Docker and fastboot. You can either make sure you stop all containers before shutting Windows down or you can disable fastboot in Windows' power settings by doing the following:

CTRL+R > "powercfg.cpl" > "Choose what the power buttons do" > "Change settings that are currently unavailable" > Deselect "Turn on fast start-up"

You can also disable fastboot with a single command in powershell if you're comfortable doing so:

Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Power\' -Name HiberbootEnabled -Value 0

Comments

1

For me, a simple

ddev poweroff

fixed this.

Comments

0

If you launched a container in VS Code or via the terminal in VS Code - shut down VS Code. I don't know if it's a clever extension or a clever built-in but VS Code insisted on blocking that port after I had launched Docker once. Also after I had close down the container. And pruned stopped containers (multiple times).

Comments

0

Tried everything listed here. My case was:

  • I couldn't see the port in use in my system. Docker said it bound but nothing was showing up
  • I couldn't find the container unless I used docker ps -a as mentioned by https://stackoverflow.com/a/57135023/5261173
  • Then eventually used docker rm [containerID]. docker stop [containerID] didn't work for unknown reasons

3 Comments

This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review
@Koedlt How does this not answer the question, I don't get? It's a bind issue as explained but the question wasn't looking for an explanation. It was looking for a fix. I went through all the answers and no particular one worked for me. I hacked my way for about 10 mins and found a solution for myself.
The question refers to an error message they are trying to solve. You refer to multiple things: you couldn't see the port (what do you mean by "see"? which port? ...?). Then you go on by specifying 2 commands: docker ps -a and docker rm. But you do not explain if or how these solve the issues the OP is getting. It seems like the comment you posted here already contains more useful information than the answer itself. So don't hesitate to rewrite your answer :) Also don't feel discouraged, we try to strive for high quality answers here. Thanks for contributing!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.