Home Docker How To Manage Docker Containers Using Portainer In Linux

How To Manage Docker Containers Using Portainer In Linux

Poratiner - An Easiest Way To Manage Docker And Kubernetes

By sk
Published: Last Updated on 4.3K views

In this tutorial, we will learn what is Portainer, how to install Portainer and how to manage docker containers using Portainer in Linux.

What Is Portainer?

Portainer is a lightweight, cross-platform, and open source management UI for Docker, Swarm, Kubernetes, and ACI environments.

Portainer allows you to manage containers, images, networks and volumes via simple web-based dashboard and/or an extensive API.

Using Portainer, we can easily deploy, configure and secure containers in minutes on Docker, Kubernetes, Swarm and Nomad in any cloud, datacenter or device.

It was originally the fork of Docker UI. The developer has rewritten pretty much all of the Docker UI original code. He also has revamped the UX completely and added some more functionality in the recent versions.

Portainer is available in two editions: Portainer Community Edition(CE) and Portainer Business Edition(BE).

The Portainer CE is free for personal use that includes a few essential features for container management. And the Portainer BE is paid version that includes complete features and professional support.

Portainer supports GNU/Linux, Microsoft Windows, and macOS.

Prerequisites

For the purpose of this guide, we will be using Portainer CE, which is free.

1. Make sure you have installed Docker and it is working. Portainer has full support for Docker version 1.10 and higher versions.

To install Docker in Linux, refer the following links.

Heads Up: You can also install Docker desktop and then install Portainer as an extension via the market place. But this is not the scope of this guide.

2. Make sure you have sudo or root access to deploy Portainer community edition using Docker.

3. Open or allow Ports 9443, 9000 and 8000 in your router or firewall if you want to access the portainer web UI from a remote system.

Install Portainer With Docker In Linux

Portainer CE installation is pretty easy and it will take only a few minutes.

First of all, create a volume for Portainer server to store its database.

$ sudo docker volume create portainer_data

Next, run the following command to pull the latest Portainer image and start the Portainer:

$ docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest

Heads Up: By default, Portainer Server will expose the UI over port 9443 and expose a TCP tunnel server over port 8000. The latter is optional and is only required if you plan to use the Edge compute features with Edge agents.

Sample output:

portainer_data:/data portainer/portainer-ce:latest
Unable to find image 'portainer/portainer-ce:latest' locally
latest: Pulling from portainer/portainer-ce
772227786281: Pull complete 
96fd13befc87: Pull complete 
4847ec395191: Pull complete 
4c2d012c4350: Pull complete 
Digest: sha256:70a61e11a899c56f95c23f734c0777b26617729fcb8f0b61905780f3144498e3
Status: Downloaded newer image for portainer/portainer-ce:latest
4b3a95e8c999f5651dfde13b5519d19a93b143afbcd6fd1f8035af5645bd0e5f

By default, Portainer generates and uses a self-signed SSL certificate to secure port 9443. If you require HTTP port 9000 open for legacy reasons, add -p 9000:9000 to your docker run command:

$ sudo 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-ce:latest

Let us check whether the Portainer image has been pulled or not.

$ sudo docker images

Sample output:

REPOSITORY               TAG       IMAGE ID       CREATED       SIZE
portainer/portainer-ce   latest    ab836adaa325   4 weeks ago   278MB

We have now installed Portainer in our local Ubuntu system. Let us start the container using command:

Now, Portainer is running! Let us go ahead and access the Portainer UI.

Manage Docker Containers Using Portainer

Open your web browser and point it to any one of the following URLs depending upon the port number you used when starting Portainer.

  • Portainer https URL (with self-signed certificate) - http://localhost:9443/ or http://IP_Address:9443/.
  • Portainer http URL - http://localhost:9000/ or http://IP_Address:9000/.

You will be presented with a screen like below where you should set a strong password for the Portainer admin user. Enter a strong password with minimum 12 characters and click Create user button.

Create Password For Portainer Admin User
Create Password For Portainer Admin User

Choose whether you want to proceed using the local environment which Portainier is running in or connect to other environments. I don't have any other environments, so I clicked the "Get started.." button to proceed with the local environment.

Portainer Admin Dashboard
Portainer Admin Dashboard

This is how Portainer admin dashboard looks like. The dashboard home screen displays the list of connected environments. As you see in the below screeenshot, we are connected with the "local" environment.

Portainer Home
Portainer Home

Click on the local environment to see the running and stopped containers, number of downloaded docker images, number of volumes and networks.

Environment Summary
Environment Summary

You don't have to memorize docker commands. Everything can be done from the Dashboard itself.

Let us go ahead and create some containers.

Creating Containers

Make sure you're in the Local environment.

Click on the App Templates button on the left side bar. You will see some ready-made templates such as Docker image registry, Nginx, Httpd, MySQl, WordPress and a few more.

Application Templates List
Application Templates List

To deploy a Container, just click on the respective template and follow the on-screen instructions.

For instance, let us launch MySQL Container. To do so, click on the MySQL template.

Launch MySQL Template
Launch MySQL Template

Enter the Container name, select network type (e.g.bride mode), and database root user password. Click on Show advanced options and set port number. If you're not sure what to input, just leave the default values.

Finally, Click Deploy the container button to create the MySQL container.

Create MySQL Docker Container
Create MySQL Docker Container

Once the container created, you will be redirected to the Containers page where you can see the list of created and running containers.

Container List
Container List

Under the Containers list section, you will see the,

  • Name of the running and stopped containers,
  • Status of the containers,
  • Quick actions buttons,
  • Docker image used to create the containers,
  • the date and time of container creation,
  • IP address of the container,
  • Published ports,
  • and Ownership details.

To start/stop the newly created container, just select it and hit Start/stop button on the top. You can restart, pause, and remove any Containers from this section.

Manage Containers

We can do all container management operations, such as add new container and start, stop, restart, pause, kill, remove existing containers from under Containers section.

Create And Manage Containers From Portainer
Create And Manage Containers From Portainer

You will see a few "Quick Actions" buttons next to each container. Clicking on a button will perform the respective action.

Under the Quick Actions tab, you will see the following buttons.

  • Logs - Display Container logs.
  • Inspect - Inspect container image.
  • Stats - View Container statistics.
  • Console - Access Container console.
  • Attach - Attach To Container console.
Quick Actions
Quick Actions

View Container Logs

Select a Container from the Containers list and then click Logs button under the Quick Actions tab.

Container Logs
Container Logs

Here, you can view complete log details of the Container.

Inspect Container

Click the "Inspect" button under the Quick Actions tab to inspect the container image.

Container Inspect
Container Inspect

View Container Stats

Click on the Stats button to view what's happening in the newly launched Container.

Container Statistics
Container Statistics

Access Container Console

You can easily connect to the console of your Container by clicking on the Console button.

Access Container Console
Access Container Console

Select the Shell (BASH or SH), and hit Connect button.

Connect To Console
Connect To Console

Now you will be connected to the Container's console.

Container Console
Container Console

View Container Details

To view the complete overview of any container, just click on the name of the container from the Containers list.

Container Details
Container Details

As you see in the above output, the Containers details section is further divided into the following sub-sections:

  • Actions - This section containers buttons to control the container, such as Start, Stop, Kill, Restart, Pause, Resume, Remove, Recreate, Duplicate/Edit.
  • Container status - In this section, you will container details such as the name, IP address, status of the container, when the container is created, container start time and a few more details. Under the Container status button, you will see the following controls:
    • Logs - Display Container logs.
    • Inspect - Inspect container image.
    • Stats - View Container statistics.
    • Console - Access Container console.
    • Attach - Attach To Container console.
  • Access control - View and change ownership.
  • Container health - In this section, you will see the container health status, failure count and mysqld service status.
  • Create image - This section allows you to create an image from this container. This allows you to backup important data or save helpful configurations. You'll be able to spin up another container based on this image afterward.
  • Container details - In this section, you can view the docker image used to create this container, port configuration details, and environment details etc.
  • Volumes - See the list of attached volumes to the container.
  • Networks - View network configuration details.

Please note that you can do all aforementioned management actions (i.e. View Stats/Logs, Inspect, Access Console etc.) from the "Container Details" section too.

Container Control Buttons
Container Control Buttons

Docker Images

In this section, you can view the list of downloaded docker images.

Docker Image List
Docker Image List

In this section, you can build new image, import, export and delete Docker images. To remove any image, just select it and click Remove.

Networks

Networks section allows you to add a new network, change the network type, assign/change IP address, remove existing networks.

Network List
Network List

Volumes

Here, you can view existing docker volumes, create new one, delete them if you no longer need them.

Volume List
Volume List

Events

In this section, we can view what we have done so far, such as creating a new instance, network, volume etc.

Event List
Event List

Host Overview

This section displays the Docker engine version, Host OS name, type, architecture, cpu, memory, network details etc.

Host Overview
Host Overview

Under this section, you can also configure Docker features and setup registries (i.e. Docker hub, Quay, Azure, Gitlab etc.).

Users

The users section allows us to add new users, add users to teams, view list of existing users and delete the users.

Users
Users

You can also create a team(e.g. development) in which you can add users in this team and assign different roles to the users. The roles feature is available only for Portainer Business edition.

Environments

In this section, you can add new environment, view existing environments.

Environments
Environments

In Portainer CE, you can add Docker, Kubernetes and ACI environments. In business edition, you can add two more environments called Nomad and KaaS.

Authentication Logs

The Authentication logs section shows you to user activity details. Portainer user authentication activity logs have a maximum retention of 7 days. This is actually business edition feature. If you're using community edition, you can't use this feature.

Settings

This section is dedicated for Portainer settings. In this section, you can configure Portainer settings such as,

  • define the snapshot level for containers,
  • use custom logo for Portainer dashboard,
  • specify the URL to your own template definitions file and HELM repository,
  • configure SSL certificate,
  • backup Portainer configuration etc.

Conclusion

In this detailed guide, we discussed what is Portainer, how to install Portainer, and how to use Portainer to create and manage Docker containers in Linux.

We also learned a brief overview about each section in the Portainer web dashboard. Using Portainer, you can do complete docker management either from the local system itself or a remote system.

If you want a feature rich, yet simple to use centralized Docker management solution, you should give Portainer a try.

For more details, check the official resources given below.

Resources:

Any thoughts on Portainer? Have you already tried it? Great! Let us know them in the comment section below.

You May Also Like

2 comments

TomCat January 4, 2017 - 12:06 pm

This is awesome on so many levels …

Reply
Chris Mosetick March 4, 2017 - 5:07 am

This looks really nice, thanks for the post. i’m curious to know how Portainer differs from Rancher Server. At first glance it seems to mirror Rancher Server very, very closely. I’m not sure what Portainer is offering, unless it’s optimized for single instance use rather than production use-cases, i.e. Docker for Mac vs. Production Docker workloads.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More