Creating a docker swarm and set up management dashboard using portainer and virtualbox

dockerswarm
dockerswarm

In last tutorial we had set up a simple in browser terminal for running docker commands on remote server.In today’s tutorial we are going to create a simple docker swarm using virtualbox and set up a dashboard for its management using portainer. Install docker by following this tutorial if you have not yet set up docker in your system. Next we are going to need docker-machine which can be installed by running the following commands for ubuntu:

Installation commands for mac users can be found here. Next install virtualbox by downloading it from here and running following commands in terminal:

Docker swarm typically consists of managers(which are like master servers) and workers(which are like slave servers).First we will create a manager and initialize docker swarm within manager:

Replace <MANAGER-IP> with ip address you got from running second command above which was 192.168.99.100 in my case. Copy the swarm join command somewhere, since we are going to require it in some time

Now we will create a worker vm using docker-machine which will act as slave vm and add it to swarm as worker.

If you need to get join token for adding workers or managers in future you can run the following commands:

Next we are going to set up portainer in manager1 for managing swarm services and containers:

Now go to your browser and open the following address: <MANAGER-IP>:9000 where <MANAGER-IP> is the ip address of the manager node. Set up default username and password and login into portainer. Clicking on the swarm tab will give the following output:

Portainer dashboard
Portainer dashboard

You can manage entire docker swarm,launch custom docker containers from app templates and ssh into running containers from containers tab from the portainer dashboard.

We can use portainer as a standalone application or we can launch it from the in browser terminal we created in previous tutorial. We simply need to add a new command definition in extensions to get portainer/manger ip from server as follows:

Install react-iframe module to display portainer window inside modal popup:

First we create a simple modal popup to display portainer window which is hidden by default.

Now we need to add an extension in previous tutorials setup to handle portainer command:

Going step by step the extension first runs “docker-machine ip manager1”  on remote server and gets the ip address of manager in callback response.Next we format the response to remove newline character and append port 9000 to the ip address. Finally we push the address in an iframe within dialog and make modal popup visible by setting dialogOpen to true.

Next define handleClose function to hide modal on click of Close button.

 

In a nutshell we are simply retrieving manager ip from server and opening portainer ui in an Iframe. The output looks like this:

That concludes today’s tutorial on docker administration.

Bonus Tips:

The goal of this tutorial was not only to get the reader acquainted with basic docker administration but also to show how we can further extend the capabilities of terminal to launch remote desktop apps within the browser thereby fading the line between terminal commands and dedicated softwares by adding useful capabilities to existing terminals.In real world scenarios you will have setup your own domain and proxy pass request from some domain to internal docker manager ip for access. I have not covered that in today’s tutorial for keeping it short and simple.

A couple of experiments that could be done are to show complete file browser window in popup when user types ls command or phpmyadmin/apache/mysqladmin page access on typing appropriate commands or setup openstack dashboard for managing cloud instances on remote host and giving restricted access to users for managing their cloud instances.

The eventual goal of this project on github is to provide similar such features for extending in browser terminal capabilities.You can see/fork the experimental source code for the project on github here

Connect Deeper:

In the next tutorial I will try to cover setting up custom dashboard for monitoring system performance when user runs top command in terminal using grafana. So follow our facebook page: Technoetics to get notified about future articles or subscribe to our mailing list below:

Technoetics newsletter

Get notified about upcoming articles,tips and tricks personally hand-delivered to your inbox

 

 

 

 

 

Share post-
About Saurabh Mhatre 70 Articles
Currently working in web and hybrid application development