moby: Cannot start container: Port has already been allocated

Hi,

docker 1.0.0 with aufs on 14.04 here. I haven’t found a way to reproduce it, but since upgrade to 1.0.0 I quite often get the error “port has already been allocated” when starting a container that was stopped earlier:

$ docker start n1
Error: Cannot start container n1: port has already been allocated
2014/06/17 13:07:09 Error: failed to start one or more containers

$ docker inspect n1|jq .[0].State.Running
false

$ docker inspect n1|jq .[0].HostConfig.PortBindings
{
  "7001/tcp": [
    {
      "HostPort": "7001",
      "HostIp": ""
    }
  ],
  "4001/tcp": [
    {
      "HostPort": "4001",
      "HostIp": ""
    }
  ],
  "10250/tcp": [
    {
      "HostPort": "10250",
      "HostIp": ""
    }
  ]
}

$ sudo netstat -lnp | egrep '10250|4001|7001'
$ sudo lsof -n | egrep '10250|4001|7001'

And the processes aren’t running either:

$ ps -ef|grep etc[d]
$ ps -ef|grep kubele[t]

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 79 (37 by maintainers)

Commits related to this issue

Most upvoted comments

PS: The only way to recover is restarting docker after which everything works as expected.

The issue can be reproduced easily. Whenever you try to allocate a port to a port which is already occupied, Docker complains since then even the port becomes free.

Tested with Docker 1.0 on Ubuntu 14.04

How to reproduce:

$ sudo service apache2 start #occupies port 80 $ sudo docker run -p 80:80 -i -t ubuntu:14.04 /bin/bash # first try

2014/06/19 15:53:59 Error: Cannot start container 2094c72e4485bd9f54e7f3f8de797845d6d8a43db37fd2f4f8231222e4bf377e: port has already been allocated

$ sudo service apache2 stop # frees port 80, can be verified by nmap $ sudo docker run -p 80:80 -i -t ubuntu:14.04 /bin/bash # second try

2014/06/19 15:53:59 Error: Cannot start container 2094c72e4485bd9f54e7f3f8de797845d6d8a43db37fd2f4f8231222e4bf377e: port has already been

$ sudo service docker restart $ docker run -p 80:80 -i -t ubuntu:14.04 /bin/bash # now it works root@cc4847a4c37d:/#