Red Green Repeat Adventures of a Spec Driven Junkie

Docker Swarm Visualizer

From my previous article, Docker Swarm Scaling, things were starting to get a interesting when scaling applications using Docker Swarm using the docker service scale command. It’s so easy to scale up an application with a single command.

One thing that did start getting hairy: where were those apps running? docker service ls reported the running apps, but not on which node.

docker ps on the individual node showed in detail what the node was running in terms of containers.

One thing I forgot to mention, the command docker service ps <service name> gives a more detailed report on the nodes, so there’s no need to login to each node and run docker ps. docker service ps is so handy!

vagrant@manager:~$ sudo docker service ps quizzical_zhukovsky
ID                  NAME                    IMAGE               NODE                DESIRED STATE       CURRENT STATE        ERROR               PORTS
g4hbst4i924v        quizzical_zhukovsky.1   nginx:latest        manager             Running             Running 3 days ago
xs06f0q5scyi        quizzical_zhukovsky.2   nginx:latest        worker1             Running             Running 3 days ago
p562s502kpj8        quizzical_zhukovsky.3   nginx:latest        worker1             Running             Running 2 days ago
l8ct5dfpiw2d        quizzical_zhukovsky.4   nginx:latest        worker1             Running             Running 2 days ago
vbm06ov4mfuv        quizzical_zhukovsky.5   nginx:latest        manager             Running             Running 2 days ago

This is fine for a small number of nodes, what happens when there’s greater number of apps? It grows linearly, while text is convenient, a picture is worth a thousand words!

Enter: Docker Swarm Visualizer

This is a tool I discovered from another blog. I found this to be really nifty so I want to incorporate it into the current set up I have.

Requirements

If you would like to follow along, please:

WORKER_COUNT = 0

to be:

WORKER_COUNT = 1
  • Run: vagrant up to create virtual computers: manager and worker1.

Install visualizer Image

The Docker Image for the visualizer is available at hub.docker.com/dockersamples/visualizer. This only needs to be on the manager node.

Install the visualizer on manager by running the following command on the manager node:

vagrant@manager:~$ sudo docker run -it -d -p 5000:8080 -v /var/run/docker.sock:/var/run/docker.sock dockersamples/visualizer
Unable to find image 'dockersamples/visualizer:latest' locally
latest: Pulling from dockersamples/visualizer
88286f41530e: Pull complete
...
fc01495d48ca: Pull complete
Digest: sha256:f1e6af29c436410dfa1c9a6bae4bf035152cbea251eec149c53b7a681a783d5c
Status: Downloaded newer image for dockersamples/visualizer:latest
d80a62a4c04235fe0bfaaa2c3e386547025d380e4572252ecf597dd68b914c72
vagrant@manager:~$ sudo docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
nginx                      latest              be1f31be9a87        3 weeks ago         109MB
dockersamples/visualizer   latest              179717024287        2 months ago        158MB

Start: Docker Visualizer

To get Docker Visualizer going, the following section of configuration from the Vagrantfile is important to understand:

  config.vm.define "manager" do |subconfig|
    subconfig.vm.box = BOX_IMAGE
    subconfig.vm.hostname = "manager"
    subconfig.vm.network :private_network, ip: MANAGER_IP_ADDRESS
    subconfig.vm.network "forwarded_port", guest: 3000, host: 3500
  end

Basically,

subconfig.vm.network "forwarded_port", guest: 3000, host: 3500

means that any server running inside manager using port 3000 will be accessible to the host computer on port 3500 (i.e. http://localhost:3500)

What I will do is configure the Docker Swarm visualizer web server to run on manager’s port 3000:

vagrant@manager:~$ sudo docker run -it -d -p 3000:8080 -v /var/run/docker.sock:/var/run/docker.sock dockersamples/visualizer

And this will allow us to see the visualizer on a browser by going to address: http://localhost:3500.

If everything is working, this is the expected image:

Docker Swarm Visualizer No Services

If you see something else contact me.

Add a service

A swarm without a service is pretty boring, so let’s add a service.

Use the following command to create a new nginx service:

vagrant@manager:~$ sudo docker service create nginx

erwxg0xmh25hm79u7m86fqvub
overall progress: 1 out of 1 tasks
1/1: running   [==================================================>]
verify: Service converged

vagrant@manager:~$ sudo docker service ls
ID                  NAME                  MODE                REPLICAS            IMAGE               PORTS
erwxg0xmh25h        jovial_kirch          replicated          1/1                 nginx:latest
vagrant@manager:~$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
erwxg0xmh25h        nginx:latest        "nginx -g 'daemon of…"   13 seconds ago      Up 12 seconds       80/tcp              jovial_kirch.1.g4hbst4i924vf87trvz3xwzhd

Now, the browser should display an image like:

Docker Swawrm Visualizer - Single Service

OR, the image can be like this:

Docker Swawrm Visualizer - Single Service Alternate

It may depend on how Docker Swarm would distribute the service.

Cool, a service pops up showing where its running. No need to run any commands to log into a node to see what is running and where.

Scale Service

One service is interesting, but let’s scale the service to four and see what happens:

vagrant@manager:~$ sudo docker service scale jovial_kirch=4
jovial_kirch scaled to 4
overall progress: 4 out of 4 tasks
1/4: running   [==================================================>]
2/4: running   [==================================================>]
3/4: running   [==================================================>]
4/4: running   [==================================================>]
verify: Service converged
vagrant@manager:~$ sudo docker service ls
ID                  NAME                  MODE                REPLICAS            IMAGE               PORTS
erwxg0xmh25h        jovial_kirch          replicated          4/4                 nginx:latest

Now, if we look at the browser, the Docker Swarm Visualizer would most likely show:

Docker Swarm Visualizer - FOUR services running!!!

Conclusion

Docker Swarm Visualizer is a great way to see what is going on with services on a Docker Swarm in a visual manner. There’s no need to log in to individual nodes and/or run commands.

Just run Docker Swarm Visualizer, create services, and view in a browser.

Getting Docker Swarm Visualizer incorporated into the virtual network required port mapping from Docker Swarm Visualizer’s 8080, to the guest’s 3000, to the host’s 3500. Nothing crazy, right?

Remember, Docker Swarm Visualizer is a learning tool and NEVER use in production systems.