Docker deploy will not publish port in swarm

I have a swarm created by two nodes, one manager and one worker. I would like to have a port published in the swarm, so I can access my applications, and I wonder how I achieve this.

version: '2' services: server: build: . image: my-hub.company.com/application/server:latest ports: - "80:80" 

This provides port 80 when I start docker build and it works fine, however when I start batch deployment

 docker deploy my-service 

This will not publish the port, so it just says 80 / tcp in docker ps instead of pointing to the port. Perhaps this is due to the fact that I need to connect a load balancer or run some bizarre command, or maybe add another configuration level to actually expose this port as multiple hosts.

Can someone help me figure out what I need to configure / do so that this displays the port.

My best case scenario would be that port 80 opens, and if I access it from different host names, it will send me to different applications.

Update: It seems to work if I run the following commands after deploying the application

 docker service update -p 80:80 my-service_server docker kill <my-service_server id> 

I found this repository to start the HA proxy, it seems to be excellent and is supported by the docker itself, however I cannot use this separate section for my services using the new swarm mode.

https://github.com/docker/dockercloud-haproxy

Below is described what the network should look like:

 Internet -> HAProxy -> Service_A -> Container A 

However, I can’t find a way to connect the services using the create docker create command, now it optimally looks like a way to configure the network, and when I apply this network to the service, it will select it in HAProxy.

- Marcus

+5
source share
3 answers

Swarm mode publishes ports differently. It will not display in docker ps since it does not publish the port on the host, it publishes the port for all nodes, so it can load balancing between service replicas.

You should see the port from docker service inspect my-service .

Any other service should be able to connect to my-service:80

+4
source

As I understand it at the moment, you can publish ports that update the service after creation, for example:

 docker service update my-service --publish-add 80:80 
+6
source

docker service ls displays port mappings.

0
source

All Articles