Portainer — The easy way to manage Docker

Simon Carr
Level Up Coding

--

There are still a lot of Developers and IT Professionals that have no experience with Docker. My personal experience is they think Docker is complex and challenging to manage.

In this tutorial, I’m going to demonstrate how to get Docker up and running quickly and how to simplify Docker management with the Web-Based graphical management tool, Portainer.

Docker vs Virtual Machines

Before we start, a quick overview of the difference between Docker and Virtual Machines might be helpful. If your already familiar with Docker just skip this section.

A Virtual Machine (VM) is an encapsulated operating system, running on top of another operating system. The VM uses the memory, processor and disk resources of the underlying hardware. The critical point here is that the Operating System running in the VM requires a substantial amount of the host machines resources to run. On a typical 16GB, i5 machine, you would struggle to run five virtual machines simultaneously. Even if they were not running any applications, you would quickly see a significant degradation in the performance of the underlying operating system and the VM’s start to freeze.

Docker containers, on the other hand, make use of the hardware resource through the underlying Operating System almost as though they were an installed application (That is a very simplistic description). The images used to build a Docker container are very small in comparison to a VM, often only a 40 or 50 MB. Since there is not a full operating system to maintain inside a Docker container, memory and processor resource usage is typically very low. I often have 20+ containers running on my 16GB Mac Book Pro. That would be impossible using VM’s.

Portainer

By default, we manage Docker through the command line. Portainer provides an excellent and highly informative user interface for managing all aspects of Docker. It charts, and dashboards provide realtime charts of container resource usage. Starting and managing containers and stacks can be done with a few mouse clicks.

Installing Docker

Installing on Windows

Ideally, you need to be running Windows 10 Pro to take advantage of the Windows Linux sub System. If you’re using a works computer where a lot of options are disabled, you might struggle, but see how far you get, then ask your IT administrators for help if required.

Download docker from the following URL. Choose the stable version.

Run the installer. Make sure to select WSL (Windows Sub Systems for Linux)

When the installation is complete, restart Windows.

Once the system has restarted, you might see a prompt to install an updated WSL 2 Linux Kernal. Just click the link and follow the instructions.

If you get an error about WSL not being enabled. Try the following command.

Open PowerShell as an Administrator and run

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

Installing on Linux

Linux is the preferred environment for Docker as it offers the best performance in a native environment.

Due to the many distributions of Linux and various platforms that you may be running it on, you will have to follow the instructions on the docker web site for installation. https://docs.docker.com/engine/install/ There are links on this web page that take you to specific instructions for your distribution.

Installing on macOS

You can download and install Docker desktop for Mac by visiting the following web site. https://hub.docker.com/editions/community/docker-ce-desktop-mac/

Make sure to get the Stable version.

After downloading open the .dmg installer file, drag the Docker application in the Applications folder, as shown above.

Installing Portainer

Whichever operating system you’re running, the commands from this point will be the same. Where I mention opening a terminal, I am referring to the Command Prompt on windows.

Open a terminal and run the following command to create a

docker volume create portainer_data

The above command creates a data volume on your disk that Portainer will use to save configuration data. Without it, data would be stored in the container and lost each time the container restarts.

Next, run the following the command to download and run the Portainer image and start up the Portainer Container.

docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

Connecting to Portainer

Installing Portainer was easy and connecting to it, is just as easy. Open a web browser and visit http://localhost:9000

The default user name is admin as this is the first time you have logged in, you will be asked to create a new password and confirm it.

On the next screen, select Local and click Connect

The Portainer home screen

The Docker instances that Portainer knows about are displayed in the central portion of the screen. There will only be one at this time, “local”. On the left is a menu that offers many of the options you would have in the Docker command line plus many more.

Click the Local Docker instance, to see the Dashboard showing a high-level overview of what is currently running in Docker.

Unless you have already been using Docker, you won’t have much running yet.

Adding a new image and starting a container

Let’s get a MariaDB Docker container up and running to see the workflow and how easy it is.

The first thing to do is create a Volume that will hold the database data — Click Volumes in the left menu panel.

Create a volume

Click Add volume

Name the volume MariaDB and click Create the volume

Create a MariaDB Container

Click Containers in the left menu panel

Click the Add container button

Name the container MariaDB

In the image text box type mariadb:latest

Click publish a new network port

Enter 3306 for the host and container

At the bottom of the page in Advanced container settings, click Volumes, then click map additional volumes

Add the following to container and volume

  • container: /var/lib/mysql
  • volume: Select the MariaDB volume you created earlier from the dropdown, which will be namedMariaDB — local

Finally, select the Env tab and click add enviroment variable

We need to tell MariaDB what the root user password should be set too. We do this by providing an environment variable. Fill the name and value text boxes as below

  • name: MYSQL_ROOT_PASSWORD
  • value: password Please use a more suitable password!

To finish the configuration of the MariaDB container, click theDeploy the container button.

After a short while, you will be taken back to the container list and you should see your MariaDB container in the running state

Create an Adminer container

We could connect to the MariaDB container through the console and issue MySQL commands on the command line. A better way is to use a Graphical interface. I prefer adminer which we will add as a container now.

Making sure you still on the container list screen, click theAdd container button.

Name the container Adminer and enter adminer:latest as the image.

In Network ports configuration section, click publish a new network port

Enter 8080 for the host and 8080 for the container

We don’t need to make any other changes. Click Deploy the container

Checking everything works

Open your browser and navigate to http://localhost:8080

You should see the Adminer login screen

Before we try to connect, be aware that you can’t use localhost for the Server setting. Why? Because Adminer is running in its own container, localhost refers to its container. Instead, you will need to provide the IP address of your computer. In my case that is 192.168.30.100.

The username will be root, and the password is whatever you set the value of MYSQL_ROOT_PASSWORD too.

Now click Login

Congratulations, your life will never be the same! :-) Being able to bring up containers in Docker quickly and without affecting the underlying operating system, opens so many opportunities.

There are a lot of prebuilt container templates included in Portainer. If you click App Templates in the left-hand toolbar, you will find some interesting apps.

Eventually, you will be looking for a container not included in the App Templates. The first place you should look is https://hub.docker.com/.

Resource monitoring

Let's check the resource being used by MariaDB. Click Containers in the left-hand menu. Click the small chart icon next to MariaDB in the Quick Actions column.

You will see three real-time charts that cover Memory usage, CPU usage, and Network usage

Inspecting Logs

Go back to the Containers screen. Click the Document icon next to the Adminer container in the Quck actions column.

The logs you will see are the PHP web server logs for Adminer. Open the Adminer web page http://localhost:8080 and refresh the screen. You will see the logs update a second later with the latest entries.

Moving forward with Docker

There is a lot more than Portainer can do. In future tutorials, I will look at other Docker and Portainer features. To use some of the more advanced features of Docker, even with the help of Portainer, you are going to need a bit more knowledge about how Docker works and the tool docker-compose. I suggest you start by visiting https://docs.docker.com/get-started/.

Summary

To make sure you don’t miss any of my tutorials, you can follow me by clicking Simon Carr.

I hope you found this tutorial informative, and you learned what you expected. Let me know in the comments if you enjoyed it, or give me some suggestions about how the tutorial or writing style could be improved.

--

--

With over 20 years in software and infrastructure, I use this platform to pass on the valuable insights I have gained from a career devoted to technology