Monitoring Clusters Using a Visualizer

Adding a GUI service to our swarm cluster

As a developer, these services will definitely excite you. Although we are only covering the fundamentals of Docker swarm and not in-depth networking and deployment, it will feel like an advanced thing to you.

That’s alright. Now, we are going to see our swarm cluster. The image we are going to use for our cluster visualization is dockersamples/docker-swarm-visualizer.

Running on Linux#

We can deploy this image as an independent container or as a swarm service. To run as a container, follow the steps below.

Running as a container#

Type $ docker run -it -d -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock dockersamples/visualizer

This will run the container with host port 8080 mapped to the container port 8080.

Running as a service#

To run a visualizer as a service on swarm node, type, docker service create --name=viz --publish=8080:8080/tcp --constraint=node.role==manager --mount=type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock dockersamples/visualizer

Parameters:

  • --publish: mapping of host and container ports

  • --constraint: location or name of the node on which the service will be created

  • --mount: bind Docker socket to container socket to receive all the events from Docker host

This will create the service on the swarm manager node as mentioned in the constraint parameter.

Open up a browser and go to localhost:8080. You should see something like this:

Currently, there is only one node in the swarm. So, it will only show all the containers in the same node. When there are more than one node in the cluster, you will see similar boxes for each node.

Running on Windows#

The image we used earlier is not available for windows. So, there is a similar image named stefanscherer/visualizer-windows:latest which is available for windows.

On Windows, you cannot use -v to bind mount the named pipe into the container. Your Docker engine has to listen to a TCP port, eg. 2375 and you have to set the DOCKER_HOST environment variable running the container.

Here, type,

ip=(Get-NetIPAddress -AddressFamily IPv4 `
   | Where-Object -FilterScript { $_.InterfaceAlias -Eq "vEthernet (HNS Internal NIC)" } `
   ).IPAddress

To get the IP address of the Docker host, type

docker run --8080:8080 -DOCKER_HOST={ip}:2375 --name=visualizer stefanscherer/visualizer-windows

This will create a container listening on port 8080. Open up a browser and check your swarm cluster.

You might be thinking that having multiple nodes in the cluster will be great for the visualizer, but that’s okay for now. This is because to create more machines, you need a hypervisor or some spare laptops.

So, for now, just try to understand different services and their communications.

In the next lesson, we will automate all the stuff we have been doing so far. So, let’s jump to the next lesson.

Scaling Services
Automating Deployments Using Docker Stack
Mark as Completed
Report an Issue