Docker Community Forums

Share and learn in the Docker community.

Cannot connect to service with randomized port

I am having some trouble connecting to a service using Docker swarm’s randomized port. So far I have only had this problem when using Docker Desktop, I cannot reproduce this when connecting to an external node.

For example:

docker service create --publish target=9000 minio/minio server /data

If I create this service on my laptop, Docker will assign it a randomized port (lets say 30006), but I will not be able to connect to it from a web browser. Service and container information look normal.

However, if i manually assign the same port:

docker service create -p 30006:9000 minio/minio server /data

This creates a service that I can connect to from a web browser (localhost:30006).

Has anyone else experienced this issue?

Windows 10 version 2004 (OS Build 19041.388)
Docker Desktop (community) 2.3.0.4 (46911) Stable
Docker Engine: 19.03.12

I also tried adding the mode=host option, but this did not make a difference

mode=host is not working for Docker Desktop for Windows.

You got the published port by checking docker service inspect, didn’t you?

Kind of odd that the docs do not show an example where only target is specified. This looks like either a doku bug (missing example without publish=*) or it’s a bug in the cli :slight_smile:

I just did a ‘docker service ls’ to find the mapped port.

The only reference I can find about using target only is in the note section of:

You can work around this by specifying  `published`  without a port definition, which causes Docker to assign a random port for each task.

I managed to find this bug reported under Docker Desktop