Issue in --publish option in docker service create

The example in the documentation say publish option will work like
–publish mode=host,target=80,published=8080
But I get error messages as below:
invalid argument “mode=host,target=80,published=8080,protocol=tcp” for --publish: Invalid containerPort: mode=host,target=80,published=8080,protocol=tcp.

Please let me know what is the exact syntax and what are the sub options under publish option.

I think you’re referring to this example here, presumably the cAdvisor one?

I think there’s an issue in documentation – publish mode host shouldn’t allow you to specify a target and published port. So I suspect it should be revised to remove one or the other.

Excuse me, I may have mis-spoke. The cAdvisor example seems to work fine. Although traditionally --net host (non-swarm mode) means “run this container in the host computer’s network namespace”.

Is this a problem of docker version? I have Docker version 1.12.3,
I am spinning up the swarm as
docker swarm init.
Then when I try this command below, it gives me the error, target and published paraameters are also not not work
docker service create --network mynet --publish mode=host --name=myservice myimage

what works is
docker service create --network mynet --publish=61616:61616 --name=myservice myimage

Even it does not work without --network option
So, I am curious to know what the mode=host is for, and why its not working for me.

Im running docker 1.12.6 and I have the same problem

The following example runs cAdvisor as a service on each node in your swarm and exposes cAdvisor port locally on each swarm node.
$ docker service create
–mode global
–mount type=bind,source=/,destination=/rootfs,ro=1
–mount type=bind,source=/var/run,destination=/var/run
–mount type=bind,source=/sys,destination=/sys,ro=1
–mount type=bind,source=/var/lib/docker/,destination=/var/lib/docker,ro=1
–publish mode=host,target=8080,published=8080
–name=cadvisor
google/cadvisor:latest

invalid argument “mode=host,target=8080,published=8080” for --publish: Invalid containerPort: mode=host,target=8080,published=8080
See ‘docker service create --help’.

Might be – try 17.03.0-ce. But by “tradtionally” I meant “in docker run”.

According to https://docs.docker.com/engine/swarm/services/#configure-service-networking-options
You can publish a service task’s port directly on the swarm node where that service is running. This feature is available in Docker 1.13 and higher.

The question now is :

  • Using docker 1.12 how to deploy cAdvisor using swarm AND publish the port on each node ? (not using routing mesh).
    The need is to collect metrics on each node, not on a random one.