Accessing container applications in a swarm

So, now you have a swarm running with an odd number of manager nodes, and a number of worker nodes. You have deployed some swarm services to run your favorite containerized applications. What's next? Well, you just might want to access one or more of the applications running in your swarm. Perhaps you have deployed a web server application. It would be nice to be able to visit the web pages shared by that web server, right? Let's take a quick look and see how easy it is to do so.

One of the features that the swarm managers handle for us is to direct traffic to our services. In an earlier example, we set up a web service that was running three replicas in the swarm. The swarm I am currently using happens to have three manager nodes and three worker nodes. All six nodes are eligible to run workloads so when the service is started, three of the six nodes will end up running a container. If we take a look at the details of the tasks of the service using the service ps command, you can see which of the six nodes are running the web-service containers:

In this example, you can see that the web service containers are running on node 01, 02, and 04. The wonderful thing is that you don't need to know which nodes are running your service containers. You can access the service via any node in the swarm. Of course, you would expect to be able to access the container on node 01, 02, or 04, but have a look at this:

There is an unfortunate side-effect of having the ability to access a service from any node in the swarm. Can you think of what it might be? I won't keep you in suspense for long. The side effect is that you can only assign a (host) port to one service in the swarm. In our example, we are using port 8080 for our web service. That means that we cannot use port 8080 for the host port of any other service we want to run in this swarm:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset