Docker Community Forums

Share and learn in the Docker community.

Automatically binded Ports for swarm services

Hey everyone,

I can create a docker service on swarm using docker service create --replicas 2 --publish :80 --name some_name some_image

--publish :80 should connect the container port 80 to a port on the docker host >30000. Requests on docker_host:30000 will be forwarded to the container:80

Problem:
Whenever i create multiple containers in a short time the ports will be assigned ascending from 30000.
If i want to create new services after an unknown longer period of time while the previously created services are still running, swarm will connect new_container:80 to docker_host:30000 again. So then multiple services are connected to the same port on the host.

I assume that the ports >30000 that are already in use are stored somewhere and discarded after an unknown period of time.
Is there any way to configure for how long this will be stored? Or maybe a way to configure swarm so it checks which ports are already in use before connecting them?

docker version output:
Client:
Version: 1.13.0-rc7
API version: 1.25
Go version: go1.7.3
Git commit: 48a9e53
Built: Fri Jan 13 06:37:02 2017
OS/Arch: linux/amd64

Server:
Version: 1.13.0-rc7
API version: 1.25 (minimum version 1.12)
Go version: go1.7.3
Git commit: 48a9e53
Built: Fri Jan 13 06:37:02 2017
OS/Arch: linux/amd64
Experimental: false