Docker does not release ports

(On Mac, Boot2Docker, docker v 1.1.1)

Problems arose when Docker would not release the ports that it uses when assigning host ports. For example, I launch 3 containers with the same image. My docker psreturns the following:

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                                            NAMES
9875e2d28c3b        49ffc1050348        /sbin/my_init       19 hours ago        Up 1 seconds        0.0.0.0:49169->22/tcp, 0.0.0.0:49170->3306/tcp   boring_goldstine
f0a40c3bb4a1        49ffc1050348        /sbin/my_init       19 hours ago        Up 6 seconds        0.0.0.0:49167->22/tcp, 0.0.0.0:49168->3306/tcp   sleepy_wright
0fb913db3528        49ffc1050348        /sbin/my_init       19 hours ago        Up About a minute   0.0.0.0:49165->22/tcp, 0.0.0.0:49166->3306/tcp   agitated_jones

Scrolling to ports you will see that 49170 is the last port allocated.

If I stop and rm these containers and start another, Docker used the lowest port available. However, now the number continues to grow:

docker run -P -d 49ffc1050348

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                                            NAMES
82fdf0e54846        49ffc1050348        /sbin/my_init       19 hours ago        Up 3 seconds        0.0.0.0:49171->22/tcp, 0.0.0.0:49172->3306/tcp   high_euclid

How do I get it to reuse old ports?

+4
source share
1 answer

portmapper 1.1.0. 65535, BeginPortRange, 49153.

docker run -p <host port>:<container port> .

+3

All Articles