Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (29.3k points)

Suppose you have two services on your topology

  1. API

  2. Web Interface

Both supposed to be running on port 80.

On docker swarm when you create a service if you wanna access it outside the cluster you need to expose and map the port from the service to the nodes (external ports). But if you map port 80 to let's say API service then you cant map the same port for Web Interface service since it will be already mapped.

How can this be solved?

As far as I see this use case is not supported. Even though if you wanna have a big swarm cluster and through in there all your services and applications will not be possible because of this behavior.

I'm missing something? Any pattern to solve this?

1 Answer

0 votes
by (50.2k points)

IP address + port. So things get messy when multiple services are listing on (for example) port 8080.

You can handle things from each other using overlay networking in swarm mode, But there is a problem coming in when you have to connect your services to the proxy (ie:-overlay network) - at that point, it looks like things get mixed up.

The solution for these things not to get mixed up is to let the services that need to be exposed to the net use ports unique as far as the proxy-facing network is concerned.

For this, we need to follow the following example.

Create two docker networks of overlay 

docker network create --driver overlay proxy

docker network create --driver overlay my-app

Creating a proxy network

docker service create --network proxy --network my-app --name app1 myApp1DockerImage

 docker service create --name proxy \

    -p 80:80 \

    -p 443:443 \

    -p 8080:8080 \

    --network proxy \

    -e MODE=swarm \

    <imagename>/docker-flow-proxy

Now with this, you can go through the proxy networks now you can start my app service with the previous docker image so that the app1 will be running on port 8081 and app2 will be exposed on port 8080.

Browse Categories

...