port is already allocated without running containers
Expected behavior
Container creation
Actual behavior
Error: port is already allocated
Information
Diagnostic ID: 269F8ACE-C09C-4FB4-856C-8208C92B0020 Docker for Mac: 1.12.0-beta21 (Build 11019) macOS: Version 10.11.6 (Build 15G31) [OK] docker-cli [OK] app [OK] moby-syslog [OK] disk [OK] virtualization [OK] system [OK] menubar [OK] osxfs [OK] db [OK] slirp [OK] moby-console [OK] logs [OK] vmnetd [OK] env [OK] moby [OK] driver.amd64-linux
Steps to reproduce
- Run a container using
-pwith any port - in my case two containers nginx (80, 443) and a node app running on 10011 - Remove the container
- Create the same or another container on the same port
Result for command docker ps -a:

Portscan on 0.0.0.0 with docker running - But without running any container

Portscan on 0.0.0.0 without docker:

Problem remains even after uninstall beta version and install stable.
Solution:

I don't like but – It is what it is
Also seeing this when my mac sleeps and this is woken up; containers are killed (issue #85) and then when trying to restart containers using docker-compose up, I'm seeing the above error. Only fix is to restart my machine :(
same here, reset to factory defaults would fix that.
In addition to this and #85, it's making development very difficult. Any additional information/assistance I can provide to help?
The same issue on OSX 10.11.6 with Docker 1.12.1 stable
@sergeyklay could you upload diagnostics from a reproduction on 1.12.1? The diagnostics in 1.12.1 are much better than in 1.12.0, in particular they include a process list from inside the VM which would show ports being held open from there. (The port opening is requested by the docker engine by running a proxy process, which communicates with a server on the Mac which actually opens the port. When the process inside the VM quits, the ports are closed on the Mac)
It would also really help if someone could help me reproduce this. Has anyone got a simple script or compose file they could share? Every time I try to repro this it always seems to work as expected :(
For example if I run an nginx in one terminal:
$ docker run -it -p 80:80 -p 443:443 nginx
and then in another terminal
$ curl http://localhost
... lots of html ...
I can see the ports bound via netstat:
$ netstat -an | less
Active Internet connections (including servers)
Proto Recv-Q Send-Q Local Address Foreign Address (state)
tcp4 0 0 *.80 *.* LISTEN
tcp4 0 0 *.443 *.* LISTEN
...
I can then Control+C the docker run and the ports go away. If I run docker run again it all comes back as expected :(
For a more complicated example, if I clone the example-voting-app:
$ git clone git://github.com/docker/example-voting-app
Cloning into 'example-voting-app'...
remote: Counting objects: 238, done.
remote: Total 238 (delta 0), reused 0 (delta 0), pack-reused 238
Receiving objects: 100% (238/238), 182.09 KiB | 0 bytes/s, done.
Resolving deltas: 100% (71/71), done.
I can repeatedly bring it up and down with
$ docker-compose up -d
# manually verify that ports 5000 and 5001 are bound
$ docker-compose down
# manually verify that ports 5000 and 5001 are free
with no error :(
Just wanted to add, I ran into this as well, but on different ports.
➜ lsof | grep 16380
com.docke 14092 cory 20u IPv4 0xc6baa1d6e0a73c6d 0t0 TCP *:16380 (LISTEN)
com.docke 14092 cory 21u IPv6 0xc6baa1d6d43e7c75 0t0 TCP localhost:16380 (LISTEN) (LISTEN)
This was with no containers running, and even after removing all containers, restarting docker, and then finally reinstalling docker for mac.
Restoring factory settings and setting everything up again now. Fortunately, that part is all automated... but it's a very odd problem.
I don't know what that was, but restoring to factory defaults did the trick!
did the trick
Ya, and removes all images, containers, volumes, networks, etc
This happen again after shutdown computer while closing docker.
On linux users have reported that after remove local-kv.db with all containers stoped the problem gets solved.
The thing is on Mac I can't find this file. On linux the path is /var/lib/docker/network/files/ but not in OsX or macOS.
Just ran into the same issue. After trying out some things, i found it. I did not want to reset my machine.
- run
docker-compose down(or similar when not using compose) to remove the network - stop docker and start again
- start container without issues (or test with
lsof -i tcp:PORTNUMBER)
I already tried by stopping all the containers, even removing all of them. The reset is a desperate measure but is the only thing that kinda works, as I say before by far is not the best but It is what it is at the moment.
@oliverhr In my case stopping containers was not sufficient. Cleaning up the remaining networks and after that stopping and starting docker fixed it. The containers are fine, it's just the lingering networks that keep blocking the ports.
Similar problem here. Container using port 3000/3001 cannot be started: "Bind for 0.0.0.0:3001 failed: port is already allocated". When I remove port 3001, I get the same message for port 3000. Happened this morning, no problems the days before, no system updates in between. Stopped/removed container, restarted docker daemon ("sudo service docker restart"), but no result.
Netstat shows this: tcp6 0 0 :::3000 :::* LISTEN 7039/docker-proxy tcp6 0 0 :::3001 :::* LISTEN 7031/docker-proxy
I start container with "-p 0.0.0.0:3000:3000 -p 0.0.0.0:3001:3001" options.
I am on a slow internet connection, so removing docker folder and recreating all images is not really an option at the moment.
The only way I can get around this is using a different port: "-p 0.0.0.0:4000:3000 -p 0.0.0.0:4001:3001".
There must be some way to release these ports??
docker version: Client: Version: 1.12.1 API version: 1.24 Go version: go1.6.3 Git commit: 23cf638 Built: Thu Aug 18 05:22:43 2016 OS/Arch: linux/amd64
Server: Version: 1.12.1 API version: 1.24 Go version: go1.6.3 Git commit: 23cf638 Built: Thu Aug 18 05:22:43 2016 OS/Arch: linux/amd64
@ctammes Did you try disconnecting or removing networks with docker network?
docker network disconnect
I checked it again, here is what i did to solve it:
- remove the network listed in
docker network ls - stop docker to release the port (after this the port should be unused on your mac)
- start docker (the port should not be in use before starting any containers)
@roelvanhintum Follwed your suggestions, but no result.
Tried to recreate image/container, but that lead to another error: Error response from daemon: oci runtime error: process_linux.go:334: running prestart hook 0 caused "exit status 1: time="2016-10-06T09:47:15+02:00" level=fatal msg="no sandbox present for 5b31e0edc7d82e0f91c9dd61d0f593337cf81bed293fd83ccc7b20f0a0062a23" \n" Error: failed to start containers
Finally removed all present containers "docker rm $(docker ps -aq)" and removed files to increase free space (I had 93% in use, after clean-up 83%). Build the images and containers without problems now.
So, maybe it is a combination of things that leads to this. I don't know if the free space really has any influence or that removing all containers did the trick.
Got the same problem again. All containers removed, stop docker engine: no ports in use, start docker engine without any containers present: ports are in use according to 'netstat -an'.
Loosing my confidence in docker ...
This are the steps I did to get the containers running again:
- stop all running containers: docker stop
- remove all containers: docker rm $(docker ps -aq)
- remove network: docker network rm
- stop daemon: sudo service docker stop
- verify no ports are in use: netstat -an | egrep ":(3000|3001|3316)"
- start daemon: sudo service docker start
- verify no ports are in use: netstat -an | egrep ":(3000|3001|3316)"
- create network: docker network create
- build/start containers: docker run --restart=always ...
But why does this happen??