25

Docker轻量级可视化管理工具Portainer

 3 years ago
source link: http://dockone.io/article/10724
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Portainer介绍

Docker的可视化管理工具有DockerUI、Shipyard、Rancher、Portainer等,具体的功能差异请查看《 Docker的可视化管理工具对比 》,本文使用Portainer工具对Docker环境进行管理。

Portainer是一个轻量级的Docker环境管理UI,可以用来管理Docker宿主机和Docker Swarm集群。

Portainer主要功能:

  • 提供状态显示面板:显示主机或者Swarm集群上有多少镜像,容器、网络、数据卷等;
  • 应用模板快速部署:可以使用预存的模板或者自己定制的模板快速部署;
  • 镜像网络数据卷管理:通过页面进行管理和操作,例如构建镜像,增删数据卷等;
  • 事件日志显示:对任何操作有记录,并且有页面可以显示审计日志;
  • 容器控制台操作:查看容器,启停容器,查看容器占用的性能(内存,CPU等)
  • Swarm集群管理:可以管理Swarm集群,是最大的优点;
  • 登录用户管理:有完备的用户系统,权限控制(高级功能需付费)。

页面功能如下图:

7Ff6ze.png!mobile

管理单台Docker主机

本文基础环境:

$ cat /etc/redhat-release 

CentOS Linux release 7.6.1810 (Core) 

$ uname -r 

3.10.0-957.5.1.el7.x86_64

$ docker -v

Docker version 19.03.1, build 74b1e89

部署Portiner容器:

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

e2563719b606ef475a7fb691aee9e3e2f1d36f76ad28588dc8127f92c4b61473
  • -v /var/run/docker.sock:/var/run/docker.sock:挂载本地 /var/run/docker.socker与容器的/var/run/docker.socker连接
  • -v portainer_data:/data:数据持久化

配置管理用户:

aaQVNf6.png!mobile

选择管理模式,由于这里是单台Docker主机,我们选择Local 本机即可:

Q32Q32j.png!mobile

进入管理页面:

vIfqQjr.png!mobile

Docker API 方式管理多台主机

Docker节点主机需开启Docker API端口,这种方式需要重启当前的Docker服务,但节点主机无需单独部署Agent服务。

$ vim /usr/lib/systemd/system/docker.service 

[Unit]

Description=Docker Application Container Engine

Documentation=https://docs.docker.com

After=network-online.target firewalld.service

Wants=network-online.target



[Service]

Type=notify

# the default is not to use systemd for cgroups because the delegate issues still

# exists and systemd currently does not support the cgroup feature set required

# for containers run by docker

ExecStart=/usr/bin/dockerd  -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

........

在ExecStart启动项添加如下内容:

-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock 

重启Docker加载配置:

$ systemctl daemon-reload

$ systemctl restart docker

$ ss -ntulp|grep 2375

tcp    LISTEN     0      128      :::2375                 :::*                   users:(("dockerd",pid=24991,fd=5))

部署Portainer容器:

$ docker run -d   -p 9000:9000 --name portainer --restart=always -v  portainer_data:/data portainer/portainer

299854fcf045c62f6ddbae2c3d8e27ec4fed1f50efb7a80a6eed3c9b9a670ce3

选择管理模式,添加远程Docker主机:

22iaEj6.png!mobile

Portainer页面Endpoints菜单通过Docker API添加其他Docker主机:

ZjEzYni.png!mobile

MrimUvn.png!mobile

miqYju7.png!mobile

Agent方式管理多台主机

由于Docker API方式需要重启Docker服务,会影响现有应用运行,可以采用Agent 方式管理。

管理节点部署Master:

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

e2563719b606ef475a7fb691aee9e3e2f1d36f76ad28588dc8127f92c4b61473
  • -v /var/run/docker.sock:/var/run/docker.sock:挂载本地 /var/run/docker.socker与容器的/var/run/docker.socker连接
  • -v portainer_data:/data:数据持久化

节点主机部署Agent:

$ docker run -d -p 9001:9001 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker/volumes:/var/lib/docker/volumes portainer/agent

299854fcf045c62f6ddbae2c3d8e27ec4fed1f50efb7a80a6eed3c9b9a670ce3

在Portainer管理页面添加Agent主机:

niMzaif.png!mobile

Rr2aAn.png!mobile

原文链接: https://www.jianshu.com/p/8c4e644e36f9 ,作者:Anson前行


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK