1

I need your help to know if I'm understanding correctly the way docker publishing works.

I created a custom Image with Dockerfile. The Dockerfile is as follows:

FROM mcr.microsoft.com/dotnet/framework/wcf:4.8
COPY ./ .
RUN "C:\assets\vc_redist.x64.exe" /quiet /install
WORKDIR /ServicioOcr .
RUN powershell -NoProfile -Command \    
Import-module IISAdministration; \    
New-IISSite -Name "ServicioOcr" -PhysicalPath C:\ServicioOcr -BindingInformation "*:1990:"; \ 
Add-WindowsFeature NET-WCF-HTTP-Activation45 
ENTRYPOINT ["C:\\KeepAlive.exe"]
EXPOSE 1990

Then I run a container publishing the exposed ports without problems:

d96e49d67157        ocrserviceimage:v1   "C:\\ServiceMonitor.e"   3 hours ago         Up 2 hours          80/tcp, 808/tcp, 0.0.0.0:2019->1990/tcp   ocrservcont

Then, I created a Docker Service, so I could have multiple replicas of the containers that host the service, using the following command:

docker service create --name=SWARM_OCR_SERVICE ocrserviceimage:v8 --publish 2020:1990

Then I get the container running inside the service, so I check if the port was published correctly, but it wasn't

shkmfrrodg1a        SWARM_OCR_SERVICE.1       ocrserviceimage:v8   BAZ1573221          Running             Running 2 hours ago 

As I understand, the way Docker Service should work is the following:

  • Docker Service creates number of specified replicas inside it. Each replica running a separated instance of the service.
  • Service inside the containers should be available through published ip:port.
  • Requests are made to the published ip:port, and then being forwarded to an available replica/container that can handle it.

Is my understanding right?

Thanks in advance.

Giovany
  • 11
  • 1

1 Answers1

0

To make sure service port was published run:

docker service inspect --format="{{json .Endpoint.Spec.Ports}}" [service_id]
  • Docker Service creates number of specified replicas inside it. Each replica running a separated instance of the service.

Yes. I would say it differently though. Docker swarm creates specified number of replicas. Number of replicas is a desired state docker swarm enforces.

  • Service inside the containers should be available through published ip:port.

Your application inside the service replicas (individual containers) should be available through published port.

  • Requests are made to the published ip:port, and then being forwarded to an available replica/container that can handle it.

Yes. Suppose you ran your service on your machine identified by ip. Once you published a port, some http client can access service replicas by ip:[published_port]

Docker swarm forwards requests to each service replica using the routing mesh unless you bypassed it. If you do bypass the routing mesh, you will be able to run only one service replica with published port per host vm. If you use the routing mesh (default) when you publish service port, you can have multiple service replicas on one host vm.

To see the routing mesh in work run:

docker service create \
  --name my-web \
  --publish published=8080,target=80 \
  --replicas 2 \
  nginx

Inspect the service logs: docker service logs -f my-web

Then try to send multiple requests to localhost:8080/[any_url] from 2 different browsers and inspect the service logs from previous step.

You should see that both service replicas serve your requests on ip:[published_port] thanks to routing mesh.

rok
  • 9,403
  • 17
  • 70
  • 126