用 Portainer.io 来监控和管理 Docker 容器（1）
容器 Docker
![](/data/attachment/album/202009/20/225425zaepvexqvg7nndqv.jpg)


随着 Docker 的使用量越来越大，监控 Docker 容器正在变得更有挑战性。每天都有大量的 Docker 容器被创建，因此如何监控它们就变得非常重要。目前已经有一些内置的工具和技术，不过对它们进行配置有一些复杂。随着基于微服务的架构正在变成接下来事实上的标准，学会这种技术将为你的知识库再添一项新技能。


基于上述场景，对一种轻量、健壮的镜像管理工具的需求日益增加。Portainer.io 解决了这个问题。 Portainer.io（最新版本是 1.20.2）非常轻量，只需 2-3 个命令就可以配置好，已经在 Docker 用户中流行起来。


比起其他工具，这个工具有很多优势，其中一些如下所示：


* 轻量（安装此工具仅需 2 到 3 个命令，与此同时安装镜像的大小在 26 M 到 30 M 之间）
* 健壮且易用
* 可用于 Docker 监控和构建
* 提供对 Docker 环境的详细概况
* 可以管理容器、镜像、网络和卷
* Portainer 部署方便，仅需一个 Docker 命令（可以在任意地方运行）
* 可以对完整的 Docker 容器环境进行监控


Portainer 同时具有以下服务：


* 社区支持
* 企业支持
* 与合作伙伴 OEM 服务一起的专业服务


Portainer 的功能和特性如下：



```
1. 配备了漂亮的仪表盘，易于使用和监控
2. 自带大量内置模板，便于操作和创建
3. 服务支持（仅 OEM 和企业用户）
4. 对容器、镜像、网络、卷以及配置进行几乎实时的监控
5. 包含 Docker 集群监控功能
6. 功能多样的用户管理

```

另请阅读：[如何在 Ubuntu 16.04 / 18.04 LTS 版本中安装 Docker CE](https://www.linuxtechi.com/how-to-setup-docker-on-ubuntu-server-16-04/)


### 如何在 Ubuntu Linux / RHEL / CentOS 系统上安装和配置 Portainer.io


注意：下面的安装过程是在 Ubuntu 18.04 上完成的，但是对 RHEL 和 CentOS 同样适用，同时假设你已经在系统上安装了 Docker CE。



```
root@linuxtechi:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04 LTS
Release:        18.04
Codename:       bionic
root@linuxtechi:~$

```

为 Portainer 创建卷：



```
root@linuxtechi:~$ sudo docker volume create portainer_data
portainer_data
root@linuxtechi:~$

```

使用下面的 Docker 命令来运行 Portainer 容器：



```
root@linuxtechi:~$ sudo docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
Unable to find image 'portainer/portainer:latest' locally
latest: Pulling from portainer/portainer
d1e017099d17: Pull complete
0b1e707a06d2: Pull complete
Digest: sha256:d6cc2c20c0af38d8d557ab994c419c799a10fe825e4aa57fea2e2e507a13747d
Status: Downloaded newer image for portainer/portainer:latest
35286de9f2e21d197309575bb52b5599fec24d4f373cc27210d98abc60244107
root@linuxtechi:~$

```

安装完成之后，通过主机或 Docker 的 IP 加上 Docker 引擎使用的 9000 端口在浏览器中打开 Portainer。


注意：如果 Docker 所在主机的系统防火墙开启，需要确保 9000 端口被放行，否则浏览器页面将无法打开。


在我这边，我的 Docker 主机/引擎的 IP 是 `192.168.1.16`，所以 URL 就是 `http://192.168.1.16:9000`


![Portainer-Login-User-Name-Password](/data/attachment/album/202009/20/225838tq8cpmtd12eowq6p.jpg)


在创建管理员用户时，请确保密码是 8 个字符，同时用户名为 `admin`，然后点击 “Create User”。


接下来进入如下所示的页面，选中 “Local” 矩形框。


![Connect-Portainer-Local-Docker](/data/attachment/album/202009/20/225600mtoq7ybwj7jorty3.jpg)


点击 “Connect”，


可以看到 admin 用户的漂亮首页如下所示，


![Portainer-io-Docker-Monitor-Dashboard](/data/attachment/album/202009/20/225603pr1ii82298qk17f8.jpg)


现在 Portainer 已经准备好运行和管理你的 Docker 容器了，同时也可用于容器监控。


### 在 Portainer 中管理容器镜像


![Portainer-Endpoints](/data/attachment/album/202009/20/225604mnln0al6n6pppl6m.jpg)


检查当前的状态，可以看到有两个容器已经在运行了，如果你创建另一个也会立即显示出来。


像下面这样，在命令行中启动一个或两个容器，



```
root@linuxtechi:~$ sudo docker run --name test -it debian
Unable to find image 'debian:latest' locally
latest: Pulling from library/debian
e79bb959ec00: Pull complete
Digest: sha256:724b0fbbda7fda6372ffed586670573c59e07a48c86d606bab05db118abe0ef5
Status: Downloaded newer image for debian:latest
root@linuxtechi:/#

```

然后在 Portainer 页面中点击刷新按钮（会出现一条让你确认的消息，点击上面的 “Continue”），就可以像下面高亮显示的一样看到 3 个容器了。


![Portainer-io-new-container-image](/data/attachment/album/202009/20/225607zlovxvzgo7gxn2oo.jpg)


点击上图中红圈圈出来的 “containers”，下一个页面会显示 “Dashboard Endpoint summary”。


![Portainer-io-Docker-Container-Dash](/data/attachment/album/202009/20/225609lrpx7uu3q5yjudev.jpg)


在这个页面中，点击上图高亮和红圈圈出来的 “Containers”，就可以对容器进行监控了。


### 以简单的方式对容器进行监控


继续上面的步骤，就会出现一个如下所示精致、漂亮的 “Container list” 页面。


![Portainer-Container-List](/data/attachment/album/202009/20/225611abxa8995rd8pbmzw.jpg)


所有的容器都可以在这里进行控制（停止、启动等等）。


1、在这个页面上，停止我们之前启动的 “test” 容器（这是一个我们早先启动的 debian 容器）。


选中此容器前面的复选框，然后点击上面的“Stop”按钮来停止。


![Stop-Container-Portainer-io-dashboard](/data/attachment/album/202009/20/225613t4e5vsh3yszd4ssd.jpg)


在命令行中，你也会看到这个容器现在已经停止或退出了：



```
root@linuxtechi:~$ sudo docker container ls -a
CONTAINER ID        IMAGE                 COMMAND             CREATED             STATUS                       PORTS                    NAMES
d45902e717c0        debian                "bash"              21 minutes ago      Exited (0) 49 seconds ago                             test
08b96eddbae9        centos:7              "/bin/bash"         About an hour ago   Exited (137) 9 minutes ago                            mycontainer2
35286de9f2e2        portainer/portainer   "/portainer"        2 hours ago         Up About an hour             0.0.0.0:9000->9000/tcp   compassionate_benz
root@linuxtechi:~$

```

2、现在，在 Portainer 页面中启动已经停止的两个容器（test 和 mycontainer2）


选中已停止的这两个容器前面的复选框，然后点击 “Start”。


![Start-Containers-Portainer-GUI](/data/attachment/album/202009/20/225614gek8915ae0z1auwm.jpg)


你会立即看到两条窗口提醒，内容是“容器成功启动”，并且两个容器的状态变为正在运行。


![Conatiner-Started-successfully-Portainer-GUI](/data/attachment/album/202009/20/225616ngmku0eywepedqew.jpg)


### 一步步探索其他多种选项和特性


1、点击高亮的“Images”，你会看到如下页面：


![Docker-Container-Images-Portainer-GUI](/data/attachment/album/202009/20/225617cgleziyadg9eqqfl.jpg)


这是可用的容器列表，其中一些可能没在运行。这些容器可以被导入、导出或者上传到不同的位置，截图如下所示。


![Upload-Docker-Container-Image-Portainer-GUI](/data/attachment/album/202009/20/225619efzqrimimfgy4mrg.jpg)


2、点击高亮的“Volumes”，显示如下页面：


![Volume-list-Portainer-io-gui](/data/attachment/album/202009/20/225621kil31ptm8zfne232.jpg)


3、通过下面的操作，可以很容易的添加卷。点击添加卷按钮，出现如下页面，在名称输入框中输入卷名称，例如 “myvol”，然后点击 “Create the volume” 按钮：


![Volume-Creation-Portainer-io-gui](/data/attachment/album/202009/20/225625i2o2w2xxz2aw8h6p.jpg)


新创建的卷如下所示（状态为未使用）：


![Volume-unused-Portainer-io-gui](/data/attachment/album/202009/20/225626c06434g9sl4ps6c0.jpg)


### 结论


通过上面的安装步骤，你可以到配置和使用 Portainer.io 的多种选项是多么简单和精美，它提供了用于构建和监控 Docker 容器的多种功能和选项。如前所述，这个一个非常轻量的工具，因此不会给主机系统增加任何负担。下一组选项将在本系列的第 2 部分中进行探讨。


另请阅读: [用 Portainer.io 来监控和管理 Docker 容器（2）](https://www.linuxtechi.com/monitor-manage-docker-containers-portainer-io-part-2/)




---


via: https://www.linuxtechi.com/monitor-manage-docker-containers-portainer-part1/


作者：[Shashidhar Soppin](https://www.linuxtechi.com/author/shashidhar/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[jlztan](https://github.com/jlztan) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
As **Docker** usage and adoption is growing faster and faster, monitoring **Docker container** images is becoming more challenging. As multiple Docker container images are getting created day-by-day, monitoring them is very important. There are already some in built tools and technologies, but configuring them is little complex. As micro-services based architecture is becoming the de-facto standard in coming days, learning such tool adds one more arsenal to your tool-set.

Based on the above scenarios, there was in need of one light weight and robust tool requirement was growing. So Portainer.io addressed this. “**Portainer.io**“,(Latest version is 1.20.2) the tool is very light weight(with 2-3 commands only one can configure it) and has become popular among Docker users.

**This tool has advantages over other tools; some of these are as below**,

- Light weight (requires only 2-3 commands to be required to run to install this tool) {Also installation image is only around 26-30MB of size)
- Robust and easy to use
- Can be used for Docker monitor and Build
- This tool provides us a detailed overview of your Docker environments
- This tool allows us to manage your containers, images, networks and volumes.
- Portainer is simple to deploy – this requires just one Docker command (can be run from anywhere.)
- Complete Docker-container environment can be monitored easily

**Portainer is also equipped with**,

- Community support
- Enterprise support
- Has professional services available(along with partner OEM services)

**Functionality and features of Portainer tool are,**

- It comes-up with nice Dashboard, easy to use and monitor.
- Many in-built templates for ease of operation and creation
- Support of services (OEM, Enterprise level)
- Monitoring of Containers, Images, Networks, Volume and configuration at almost real-time.
- Also includes Docker-Swarm monitoring
- User management with many fancy capabilities

**Read Also : How to Install Docker CE on Ubuntu 16.04 / 18.04 LTS System**

#### How to install and configure Portainer.io on Ubuntu Linux / RHEL / CentOS

**Note: **This installation is done on Ubuntu 18.04 but the installation on RHEL & CentOS would be same. We are assuming Docker CE is already installed on your system.

```
shashi@linuxtechi:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04 LTS
Release: 18.04
Codename: bionic
shashi@linuxtechi:~$
```

Create the Volume for portainer

```
shashi@linuxtechi:~$ sudo docker volume create portainer_data
portainer_data
shashi@linuxtechi:~$
```

Launch and start Portainer Container using the beneath docker command,

```
shashi@linuxtechi:~$ sudo docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
Unable to find image 'portainer/portainer:latest' locally
latest: Pulling from portainer/portainer
d1e017099d17: Pull complete
0b1e707a06d2: Pull complete
Digest: sha256:d6cc2c20c0af38d8d557ab994c419c799a10fe825e4aa57fea2e2e507a13747d
Status: Downloaded newer image for portainer/portainer:latest
35286de9f2e21d197309575bb52b5599fec24d4f373cc27210d98abc60244107
shashi@linuxtechi:~$
```

Once the complete installation is done, use the ip of host or Docker using port 9000 of the Docker engine where portainer is running using your browser.

**Note:** If OS firewall is enabled on your Docker host then make sure 9000 port is allowed else its GUI will not come up.

In my case, IP address of my Docker Host / Engine is “192.168.1.16” so URL will be,

http://192.168.1.16:9000

Please make sure that you enter 8-character passwords. Let the admin be the user as it is and then click “Create user”.

Now the following screen appears, in this select “Local” rectangle box.

Click on “Connect”

Nice GUI with admin as user home screen appears as below,

Now Portainer is ready to launch and manage your Docker containers and it can also be used for containers monitoring.

#### Bring-up container image on Portainer tool

Now check the present status, there are two container images are already running, if you create one more that appears instantly.

From your command line kick-start one or two containers as below,

```
shashi@linuxtechi:~$ sudo docker run --name test -it debian
Unable to find image 'debian:latest' locally
latest: Pulling from library/debian
e79bb959ec00: Pull complete
Digest: sha256:724b0fbbda7fda6372ffed586670573c59e07a48c86d606bab05db118abe0ef5
Status: Downloaded newer image for debian:latest
root@d45902e717c0:/#
```

Now click Refresh button (Are you sure message appears, click “continue” on this) in Portainer GUI, you will now see 3 container images as highlighted below,

Click on the “**containers**” (in which it is red circled above), next window appears with “**Dashboard Endpoint summary**”

In this page, click on “**Containers**” as highlighted in red color. Now you are ready to monitor your container image.

#### Simple Docker container image monitoring

From the above step, it appears that a fancy and nice looking “Container List” page appears as below,

All the container images can be controlled from here (stop, start, etc)

**1)** Now from this page, stop the earlier started {“test” container (this was the debian image that we started earlier)}

To do this select the check box in front of this image and click stop button from above,

From the command line option, you will see that this image has been stopped or exited now,

```
shashi@linuxtechi:~$ sudo docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d45902e717c0 debian "bash" 21 minutes ago Exited (0) 49 seconds ago test
08b96eddbae9 centos:7 "/bin/bash" About an hour ago Exited (137) 9 minutes ago mycontainer2
35286de9f2e2 portainer/portainer "/portainer" 2 hours ago Up About an hour 0.0.0.0:9000->9000/tcp compassionate_benz
shashi@linuxtechi:~$
```

**2)** Now start the stopped containers (test & mycontainer2) from Portainer GUI,

Select the check box in front of stopped containers, and the click on Start

You will get a quick window saying, “**Container successfully started**” and with running state

#### Various other options and features are explored as below step-by-step

**1)** Click on “**Images**” which is highlighted, you will get the below window,

This is the list of container images that are available but some may not running. These images can be imported, exported or uploaded to various locations, below screen shot shows the same,

**2)** Click on “**volumes”** which is highlighted, you will get the below window,

**3)** Volumes can be added easily with following option, click on add volume button, below window appears,

Provide the name as “**myvol**” in the name box and click on “**create the volume**” button.

The newly created volume appears as below, (with unused state)

##### Conclusion:

As from the above installation steps, configuration and playing around with various options you can see how easy and fancy looking is Portainer.io tool is. This provides multiple features and options to explore on building, monitoring docker container. As explained this is very light weight tool, so doesn’t add any overload to host system. Next set-of options will be explored in part-2 of this series.

Read Also: [Monitor and Manage Docker Containers with Portainer.io (GUI tool) – Part-2](https://www.linuxtechi.com/monitor-manage-docker-containers-portainer-io-part-2/)