Docker Community Forums

Share and learn in the Docker community.

Will docker service support: -P, --publish-all

beta
docker

(Cohenaj194) #1

Will the new version of docker swarm in docker 1.12 support the -P, --publish-all option? If not how would I have my docker service containers get a random port when it needs one? As of right now all docker services I run will simply attach themselves to the port I assign with -p, for example -p 80:80 .

For reference here is the --help entry for -P, --publish-all in the last version of docker:
-P, --publish-all Publish all exposed ports to random ports


(Andrenth) #2

You can get a random port using -p :80


(Cohenaj194) #3

For some reason I get an error message when trying to do this, here is my create command:

docker service create --replicas 1 --name apa-sim -p :80 cohenaj194/apache-simple
The container created has the following port configuration:
PORTS 80/tcp

And here is the resulting error in the logs of the container created:
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.255.0.8. Set the 'ServerName' directive globally to suppress this message

All of this works just fine when I do a regular docker run command.


(Andrenth) #4

I don’t know how to help you further then :cry:

I’ve done tests using jwilder/whoami and nginx images (-p :8000 and -p :80, respectively) and a port starting at 30000 was assigned in both cases.


(Cohenaj194) #5

This seems to be an issue with the latest update of docker 1.12, see this github post.


(Cohenaj194) #6

I found the solution. docker services require a docker network to be reachable. Follow these two steps and the service nodes will work, heres how it would work with my service:

docker network create -d overlay mynet
docker service create --replicas 1 --name apa-sim -p :80/tcp –-network mynet cohenaj194/apache-simple

Afterwards all your service containers that are on any one node will all be automatically be load balanced between port 80 on that one node.

Heres a great guide talking about this: https://feiskyer.github.io/2016/06/24/Play-with-docker-v1-12/