Port mappings are not released

Expected behavior

Port mappings are released immediately when containers are stopped or removed, allowing the ports to be reused by other containers or system services.

Actual behavior

Port mappings to not seem to be released immediately when containers stop. They are released eventually, but in my testing it can take up to a few minutes for them to free.

Information

OS X: version 10.11.4 (build: 15E65)
Docker.app: version v1.11.0-beta9
Running diagnostic tests:
[OK]      docker-cli
[OK]      Moby booted
[OK]      driver.amd64-linux
[OK]      vmnetd
[OK]      osxfs
[OK]      db
[OK]      slirp
[OK]      menubar
[OK]      environment
[OK]      Docker
[OK]      VT-x
Docker logs are being collected into /tmp/20160430-003412.tar.gz
Most specific failure is: No error was detected
Your unique id is: AE4B724B-B3E8-460E-9BB1-9B1F5186B593

Steps to reproduce the behavior

Running from a freshly reset installation of beta-9:

Kuiper:~ rnixon$ docker run --rm -p 80:80 nginx
172.17.0.1 - - [30/Apr/2016:07:26:48 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.86 Safari/537.36" "-"
172.17.0.1 - - [30/Apr/2016:07:26:48 +0000] "GET /favicon.ico HTTP/1.1" 404 571 "http://localhost/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.86 Safari/537.36" "-"
2016/04/30 07:26:48 [error] 6#6: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "localhost", referrer: "http://localhost/"

^CKuiper:~ rnixon$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

Kuiper:~ rnixon$ docker run --rm -p 80:80 nginx
docker: Error response from daemon: driver failed programming external connectivity on endpoint modest_einstein (3370d28abe5e44be19af75da2c8ae96d6c977538fb98ccff8ec029b4e3e9a8bb): Error starting userland proxy: Failed to bind: EADDRINUSE.

I can consistently reproduce the EADDRINUSE error provided that I:

  • Use the port mapping at least once before removing the container (in the example I’m visiting the Nginx landing page)
  • Attempt to run a new container within ~60 seconds of removing the previous container.

It seems as though the port mapping is removed immediately if I do not make any requests over it before removing the container.

7 Likes

Can confirm I have seen this before as well.

I need to troubleshoot further…

I have this problem sometimes too. It happened to me when I did a docker-compose restart [service].
I can’t reproduce it reliably.

I can confirm I’m facing the same issue here.

I have the same issue here…

I can confirm that this bug happened to me. But why don’t you try the following:

$ docker ps -a

In the output I’ve had a dead/zmobie/alive/whatever process that wanted to take the port 80 for some reasons:

28e40ca16e2a        node:0.12.9         "node node_modules/.b"   8 weeks ago         Exited (137) 5 weeks ago          0.0.0.0:80->80/tcp   ambmathjax_main_1

I did the usual magic kill them all command to release it:

$ docker rm -fv $(docker ps -aq)

It worked fine after then.

You could just do $ docker rm 28e40ca16e2a instead, but I felt like killing them all instead.

Has this got better in the latest beta? I think there were some fixes here but not sure, if not I will raise an issue, especially if you can provide a means to reproduce.

Still reproducible in beta10, same as @taiidani originally reported for beta9.

Seeing this EADDRINUSE error pretty much every time I stop / start my container as well. Never saw that error with the docker toolbox before. This seems to be the most annoying issue for me at the moment, really hoping it gets fixed quickly.

I can confirm this is still occurring. Tested with nginx (port 80) using docker-compose.

Manually stopping and removing the containers did not resolve the issue.

Docker for Mac: 1.11.1-beta10 (build: 6662)
OS X: El Capitain

I just ran into this today as well.

Docker for Mac: 1.11.1-beta10 (build: 6662)
OS X: El Capitain

To add to @pierce in my env I’m noticing that manually stopping and removing the containers did not resolve the issue either, but I think it’s because the container I was trying to start when i received the error got in a “Created” state and had to be removed as well before the port was released and I could docker run again.

Here’s some console output from when I was diagnosing:

`Juns-MacBook-Pro:mml-ams-server jun$ docker run -d -p 80:80 -p 443:443 -p 1111:1111 -p 1935:1935 e2c35cafd4dd
8d6c57b24638287a23a9067af0b49c1ff6c3f869e9e6dd1bb588bf9e9c2e3c7d

Juns-MacBook-Pro:mml-ams-server jun$ docker stop 8d6c57b24638287a23a9067af0b49c1ff6c3f869e9e6dd1bb588bf9e9c2e3c7d
8d6c57b24638287a23a9067af0b49c1ff6c3f869e9e6dd1bb588bf9e9c2e3c7d

Juns-MacBook-Pro:mml-ams-server jun$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8d6c57b24638 e2c35cafd4dd “/usr/bin/supervisord” 35 seconds ago Exited (0) 5 seconds ago jovial_fermat
837f6a5f5c1b 3216e2f0fda6 “/bin/sh -c /bin/bash” About an hour ago Exited (0) 58 minutes ago determined_sinoussi
8bfad76cfcc8 8900a317fc9a “/bin/sh -c 'chmod +x” 7 days ago Exited (1) 7 days ago determined_lovelace

Juns-MacBook-Pro:mml-ams-server jun$ docker run -d -p 80:80 -p 443:443 -p 1111:1111 -p 1935:1935 e2c35cafd4dd
e089a12f1c27084c170a48bc730edf7c00176ed54fc2c26d58b3a9a5d816e016
docker: Error response from daemon: driver failed programming external connectivity on endpoint ecstatic_archimedes (8f9960951348631c5009b7f8d9e5c5c0aa60a2d0b3f1e271362e0bd4c411c2bd): Error starting userland proxy: Failed to bind: EADDRINUSE.

Juns-MacBook-Pro:mml-ams-server jun$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e089a12f1c27 e2c35cafd4dd “/usr/bin/supervisord” 22 seconds ago Created ecstatic_archimedes
8d6c57b24638 e2c35cafd4dd “/usr/bin/supervisord” About a minute ago Exited (0) 31 seconds ago jovial_fermat
837f6a5f5c1b 3216e2f0fda6 “/bin/sh -c /bin/bash” About an hour ago Exited (0) 58 minutes ago determined_sinoussi
8bfad76cfcc8 8900a317fc9a “/bin/sh -c 'chmod +x” 7 days ago Exited (1) 7 days ago determined_lovelace

Juns-MacBook-Pro:mml-ams-server jun$ docker rm e089a12f1c27
e089a12f1c27

Juns-MacBook-Pro:mml-ams-server jun$ docker rm 8d6c57b24638
8d6c57b24638

Juns-MacBook-Pro:mml-ams-server jun$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
837f6a5f5c1b 3216e2f0fda6 “/bin/sh -c /bin/bash” About an hour ago Exited (0) About an hour ago determined_sinoussi
8bfad76cfcc8 8900a317fc9a “/bin/sh -c 'chmod +x” 7 days ago Exited (1) 7 days ago determined_lovelace

Juns-MacBook-Pro:mml-ams-server jun$ docker run -d -p 80:80 -p 443:443 -p 1111:1111 -p 1935:1935 e2c35cafd4dd
5844c74eccf5e05f686e13b60fc87048e73a6243cfef2e365a4dd7a6b73b8c66

Juns-MacBook-Pro:mml-ams-server jun$ docker stop 5844c74eccf5e05f686e13b60fc87048e73a6243cfef2e365a4dd7a6b73b8c66
5844c74eccf5e05f686e13b60fc87048e73a6243cfef2e365a4dd7a6b73b8c66

Juns-MacBook-Pro:mml-ams-server jun$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5844c74eccf5 e2c35cafd4dd “/usr/bin/supervisord” 22 seconds ago Exited (0) 3 seconds ago determined_pasteur
837f6a5f5c1b 3216e2f0fda6 “/bin/sh -c /bin/bash” About an hour ago Exited (0) About an hour ago determined_sinoussi
8bfad76cfcc8 8900a317fc9a “/bin/sh -c 'chmod +x” 7 days ago Exited (1) 7 days ago determined_lovelace`

Having the same issue… How does one get the port released (or just things “clean”) when this occurs?

docker rm -fv $(docker ps -aq) is not enough.

Stopping the docker for mac daemon (from the OSX taskbar) and restarting it
works fine but is not the fastest solution :frowning:

2 Likes

Same issue here with the nginx image, and the various workarounds posted here do not solve the problem,
so I had to give up and go back to bootdocker which is unfortunate.

Version 1.11.1-beta10 (build: 6662)
El Capitan

ERROR: for nginx_instance driver failed programming external connectivity on endpoint dockerbeta_nginx_instance_1 (fb44ceb9663bc09019c1ea46d87b76c2eb50834dace7f8eb78c71abfbf057bbf): Error starting userland proxy: Failed to bind: EADDRINUSE

If the message is from Docker could the IP address that’s in use be added to the error message? Might give some kind of clue.
I changed the nginx image to an nginx debug image, but of course that made no difference.

For what it’s worth I’m still using links instead of networking.
However have tried with networking, but the error message is exactly the same.

Having the same problem. When you just recreate a container in a docker-compose setting it’s very annoying. I reverted back to using a vagrant box. Hope this is solved soon…

My guess is that the error message in my case was simply telling the bald truth (see my first message above)

The point, I suppose, is this:

bootdocker created a separate machine for docker on 192.168.99.100, whereas the docker beta uses our local, actual machine.
In my case I was still using my config as if I was still using bootdocker.

So, the ports bit in my .yml file is:
ports:
- “80:80”
- “443:443”

But my port 80 really is already occupied on my machine - by apache, and EADDRINUSE is entirely appropriate.

I thought of assigning different ports for docker like 8000 and 444, but opening ports on mac these days is too complicated.
So I shutdown Apache, which was squatting on 80 and 443, and restarted docker-compose using the original ports.

In my case this has solved the problem and no amount of stopping and starting has made it appear again.

1 Like

Your first experience wasn’t the actual bug, it was a configuration error. Run docker-compose restart [service] on that service a few times to experience the bug in all of its glory.

Add me to the list of people suffering from this bug. I’m reverting to Docker Toolbox until it’s fixed.

I guess it’s unrelated as it sounds like port 80 and 443 are the problem, but note that you can’t bind port 2375 & 62374, see:

$ screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
moby:~# netstat -tlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 :::62374                :::*                    LISTEN      1490/diagnostics-se
tcp        0      0 :::2375                 :::*                    LISTEN      1249/docker```
crazy sheep uploaded this image to

This should be fixed in Beta 11. Please let me know if the issue persists!