Docker图形页面管理工具基本常用的有三种: Docker UI,Shipyard,Portainer,之前分别介绍了Docker UI和Shipyard部署,下面简单介绍下Portainer部署.Portainer是Docker的图形化管理工具,提供状态显示面板、应用模板快速部署、容器镜像网络数据卷的基本操作(包括上传下载镜像,创建容器等操作)、事件日志显示、容器控制台操作、Swarm集群和服务等集中管理和操作、登录用户管理和控制等功能, 功能十分全面,基本能满足中小型单位对容器管理的全部需求。
0) 机器环境
[[email protected] ~]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) [[email protected] ~]# ifconfig|grep 172.16.60 inet 172.16.60.213 netmask 255.255.255.0 broadcast 172.16.60.255 [[email protected] ~]# systemctl stop firewalld [[email protected] ~]# systemctl disable firewalld [[email protected] ~]# firewall-cmd --state not running
1) 查询当前有哪些Portainer镜像
[[email protected] ~]# docker search portainer NAME DESCRIPTION STARS OFFICIAL AUTOMATED portainer/portainer A simple to use management user interface fo… 831 hypriot/rpi-portainer A web interface for the Docker engine. Dead … 36 portainer/templates App Templates for Portainer http://portainer… 14 portainer/agent An agent used to manage all the resources in… 10 portainer/golang-builder Utility to build Golang binaries. 2 [OK] bmoorman/portainer Portainer [github.com/portainer/portainer] o… 1 [OK] arpanpal010/portainer 1 usgsastro/portainer custom portainer install into centos7 1 [OK] softonic/portainer-endpoint Allows auto register all the swarm nodes in … 1 [OK] dockerframework/portainer Portainer (Simple Management UI for Docker) … 1 [OK] rancher/portainer-agent 0 voltha/voltha-portainer Portainer support for VOLTHA 0 nenadilic84/portainer 0 rodjers/portainer Swarm portainer 0 portainer/base Multi-stage build image to create the Portai… 0 [OK] hassioaddons/portainer 0 portainer/angular-builder Builder image for Portainer frontend. 0 [OK] stefanscherer/portainer Portainer for Windows Insider 0 jiangxinshang/portainer 可在loongson的mips64el平台运行的portainer 0 ssbkang/portainer 0 ollijanatuinen/portainer debug/development versions of portainer 0 helloysd/portainer 0 j0nnylester/portainer portainer running on a Raspberry Pi 0 11384eb/portainer 0 flochtililoch/armv7l-portainer 0
2) 下载Portainer镜像
[[email protected] ~]# docker pull portainer/portainer Using default tag: latest latest: Pulling from portainer/portainer d1e017099d17: Pull complete d4e5419541f5: Pull complete Digest: sha256:07c0e19e28e18414dd02c313c36b293758acf197d5af45077e3dd69c630e25cc Status: Downloaded newer image for portainer/portainer:latest [[email protected] ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 62f816a209e6 6 days ago 109MB portainer/portainer latest 00ead811e8ae 8 weeks ago 58.7MB
3) 运行Portainer,Portainer运行方式有以下两种方式:
单机版运行
如果仅有一个docker宿主机,则可使用单机版运行,运行以下命令就可以启动了:
[[email protected] ~]# docker run -ti -d --name kevin-portainer -p 9000:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer 5818eaf37bf493a679ebbaa05ba28c6a860501ea78e608981e1934300843ab4b [[email protected] ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5818eaf37bf4 portainer/portainer "/portainer" 19 seconds ago Up 2 seconds 0.0.0.0:9000->9000/tcp kevin-portainer
以上语句用宿主机9000端口关联容器中的9000端口,并给容器起名为portainer-test。启动成功后,使用该机器IP:PORT即可访问Portainer。访问http://172.16.60.213:9000, 首次登陆需要注册用户,给admin用户设置密码:
单机版这里选择local, 点击Connect进行连接即可
如上,点击左边栏的"Endpoint"-"local",可以将单机版的节点名称修改下,比如将默认的"local"改为"docker-node1-172.16.60.213"
点击"Update endpoint",就可以看到修改后新的节点名称"docker-node1-172.16.60.213"了,然后点击"Home",点击右边的docker-node1-172.16.60.213节点,就可看到该节点的Docker管理信息.
接着就可以在这个web节点里进行Docker容器的创建,更名,关闭,启动,删除以及镜像,网络,volume等操作管理了
集群运行
在有多台Docker的情况下,进行集群管理就十分重要了,Portainer也支持集群管理,Portainer可以和Swarm一起来进行集群管理操作。通过以下命令启动:
一. 先来搭建Swarm集群环境 1) 基本环境 用两台机器来搭建(都是centos7.5系统) 172.16.60.213 docker-node1 172.16.60.214 docker-node2 [[email protected] ~]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) 修改两台机器的主机名并做hosts (这里以docker-node1为例) [[email protected] ~]# hostnamectl set-hostname docker-node1 [[email protected] ~]# echo "docker-node1" > /etc/hostname [[email protected] ~]# vim /etc/hosts 172.16.60.213 docker-node1 172.16.60.214 docker-node2 关闭两台机器的防火墙和selinux (这里以docker-node1为例) [[email protected] ~]# systemctl stop firewalld [[email protected] ~]# systemctl disable firewalld [[email protected] ~]# firewall-cmd --state not running [[email protected] ~]# cat /etc/sysconfig/selinux SELINUX=disabled [[email protected] ~]# setenforce 0 [[email protected] ~]# getenforce Disabled 两台机器都要安装docker环境 (这里以docker-node1为例) [[email protected] ~]# yum install -y docker [[email protected] ~]# systemctl start docker [[email protected] ~]# systemctl disable docker 修改docker监听端口 (这里以docker-node1为例) Swarm是通过监听2375端口进行通信的,所以在使用Swarm进行集群管理之前,需要设置一下2375端口的监听。所有主机节点docker开启2375监听, docker版本不同,配置方式不一样 [[email protected] ~]# cp /lib/systemd/system/docker.service /lib/systemd/system/docker.service.bak [[email protected] ~]# vim /lib/systemd/system/docker.service //将ExecStart一行修改为下面内容: ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock [[email protected] ~]# diff /lib/systemd/system/docker.service /lib/systemd/system/docker.service.bak 13c13 < ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --- > ExecStart=/usr/bin/dockerd -H unix:// 重启docker服务 [[email protected] ~]# systemctl daemon-reload [[email protected] ~]# systemctl restart docker 2) Swarm安装和集群创建 2.1) Swarm镜像下载 docker-node1机器上下载 [[email protected] ~]# docker pull swarm [[email protected] ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE swarm latest ff454b4a0e84 5 months ago 12.7MB docker-node2机器上下载 [[email protected] ~]# docker pull swarm [[email protected] ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/swarm latest ff454b4a0e84 5 months ago 12.7 MB 2.2) 初始化Swarm 在docker-node1机器上进行初始化操作 [[email protected] ~]# docker swarm init --advertise-addr 172.16.60.213 Swarm initialized: current node (vayif0c04lged913w9z3pxtd5) is now a manager. To add a worker to this swarm, run the following command: docker swarm join --token SWMTKN-1-5qjhhernfguqc4zwhtwgdzfwy7xl1ksjr04ve2wg0pk376wqvx-717allcxbo5mu02weq0s4ge36 172.16.60.213:2377 To add a manager to this swarm, run ‘docker swarm join-token manager‘ and follow the instructions. 上面命令执行后,该机器自动加入到swarm集群。这个会创建一个集群token,获取全球唯一的 token,作为集群唯一标识。 后续将其他节点加入集群都会用到这个token值。 其中,--advertise-addr参数表示其它swarm中的worker节点使用此ip地址与manager联系。命令的输出包含了其它节点如何加入集群的命令。 2.3) 添加集群节点 在docker-node2机器上执行以下添加集群节点的操作命令 [[email protected] ~]# docker swarm join --token SWMTKN-1-5qjhhernfguqc4zwhtwgdzfwy7xl1ksjr04ve2wg0pk376wqvx-717allcxbo5mu02weq0s4ge36 172.16.60.213:2377 This node joined a swarm as a worker. 如后续要加入其他更多的节点,添加操作也是执行这个命令. 2.3) 查看集群节点 在docker-node1机器上执行查看,因为此时它是swarm集群的leader节点 [[email protected] ~]# docker node list ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION vayif0c04lged913w9z3pxtd5 * docker-node1 Ready Active Leader 18.09.0 trmbfdjdxncnukfenuzuokfun docker-node2 Ready Active 1.13.1 最后查看下两个机器上的2375端口都已经开启了 [[email protected] ~]# lsof -i:2375 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME dockerd 13785 root 5u IPv6 4518841 0t0 TCP *:2375 (LISTEN) [[email protected] ~]# lsof -i:2375 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME dockerd-c 2966 root 5u IPv6 3602947 0t0 TCP *:2375 (LISTEN) =============================================================== 二. 部署Portainer docker-node1节点操作 删除上面单机版部署的容器 [[email protected] ~]# for i in $(docker ps -a -q);do docker stop $i && docker rm $i;done e3af45ff8141 e3af45ff8141 5818eaf37bf4 5818eaf37bf4 [[email protected] ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [[email protected] ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE portainer/portainer latest 00ead811e8ae 8 weeks ago 58.7MB [[email protected] ~]# docker run -ti -d --name my-portainer -p 9000:9000 --restart=always portainer/portainer 6755cd140049d7cb3ab77f40ddf0fb79f20384cffd17cb87da68d04033be30b5 [[email protected] ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6755cd140049 portainer/portainer "/portainer" 57 seconds ago Up 41 seconds 0.0.0.0:9000->9000/tcp my-portainer
访问http://172.16.60.213:9000, 同样首次登陆需要注册用户,给admin用户设置密码:
集群模式, 这样一定要选择Remote, 输入docker-node1的ip,然后点击Connect。
同样点击左边栏的"Endpoints" - "+add endpoint", 添加集群节点
如上,发现docker-node1(172.16.60.213)节点状态是"down",排查原因:
原文地址:https://www.cnblogs.com/kevingrace/p/9953677.html