部署PORTAINER 使用官方提供的Demo预览一下 地址: http://demo.portainer.io/
一.单机部署PORTAINER 使用以下Docker命令部署Portainer:
[root@192 ~]# docker pull portainer/portainer
[root@192 ~]# docker volume create portainer_data
[root@192 ~]# docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
注意:关闭selinux虚拟机要重启,不然报错
访问网页 http://IP:9000
二.在Swarm 集群中部署
注意: 要添加镜像加速器,不然后面下载镜像时可能会报错 [root@manager ~]# vim /etc/docker/daemon.json { "registry-mirrors":["https://registry.docker-cn.com"] }
创建集群,下载基础镜像。集群中每个节点都要有portainer/agent镜像
1.创建Docker Swarm 集群 [root@manager ~]# docker swarm init --advertise-addr 192.168.10.102
[root@localhost ~]# docker pull portainer/agent ## 下载代理镜像
1.创建两个网路 [root@localhost ~]# docker network create --driver overlay portainer_agent_network [root@localhost ~]# docker network create --driver overlay my-network ○22 将代理部署为集群中的全局服务 ##节点需重新下 portainer/agent
[root@manager ~]# docker service create --name portainer_agent --network portainer_agent_network --publish mode=host,target=9001,published=9001 -e AGENT_CLUSTER_ADDR=tasks.portainer_agent --mode global --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock portainer/agent
4zmiaajed7c6vc591hcrkkksl
overall progress: 3 out of 3 tasks
i3i9p03c6zo7: running
hzorsxqq5l42: running
21hha3mf1sao: running
verify: Service converged
[root@manager ~]# docker service ps portainer_agent ##查看状态 ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS n5smvf1mfs1y portainer_agent.21hha3mf1sao77g07tpxr12lp portainer/agent:latest 192.168.0.122 Running Running 9 minutes ago *:9001->9001/tcp p5h3caz91b1i portainer_agent.i3i9p03c6zo7guhhf31ng0zkd portainer/agent:latest 192.168.0.120 Running Running 9 minutes ago *:9001->9001/tcp 87q0pzanti4q portainer_agent.hzorsxqq5l42feix3o23vk7cr portainer/agent:latest 192.168.0.126 Running Running 9 minutes ago *:9001->9001/tcp
3.Portainer 实例部署 ○3 在集群中,创建单个Portainer 可视化工具容器,默认端口9000
[root@localhost ~]# docker service create --name portainer --network portainer_agent_network --publish 9000:9000 --replicas=1 --constraint 'node.role == manager' portainer/portainer -H "tcp://tasks.portainer_agent:9001" --tlsskipverify
8ymzu530g699lnyj4bzx38me4
overall progress: 1 out of 1 tasks
1/1: running
verify: Service converged
浏览器访问 http://IP:9000 ○4 创建管理用户
○5 添加被管理节点
- 配置Endpoints Dashboard 在集群中部署niigx服务。并创建三个副本测试 [root@localhost ~]# docker service create --name ngixn-test02 --network my-network --publish 8888:80 --replicas=3 nginx image nginx:latest could not be accessed on a registry to record its digest. Each node will access nginx:latest independently, possibly leading to different nodes running different versions of the image.
uuz2q0qdet6sjee8rngi92bju
overall progress: 3 out of 3 tasks
1/3: running
2/3: running
3/3: running
verify: Service converged
在网页中可以看到详细信息
查看单个容器的系统资源
下载镜像
基于下载的镜像,创建httpd 服务
浏览器访问http://IP:90 可看出通过Portainer成功创建了httpd 服务
7 . 创建并添加私有仓库 [root@manager ~]# docker run -d -v /home/root/registry:/var/lib/registry -p 5000:5000 --restart=always --privileged=true --name registry registry:latest a7bf1601c3ebc28e1bff059638f0c9a7f602e525f55b1741f497026a56c33b31
编辑daemon.json文件,修改成私有仓库地址,三台主机上都要设置 [root@manager ~]# vim /etc/docker/daemon.json { "insecure-registries":["192.168.10.102:5000"] } [root@manager ~]# scp /etc/docker/daemon.json 192.168.10.103:/etc/docker/ [root@manager ~]# scp /etc/docker/daemon.json 192.168.10.104:/etc/docker/ 注意:三台节点上重启Docker 时,之前创建的Portainer和portainer_agent 服务将不能正常运行。 这时,需要在manager上删除此服务,在重新执行○2--○5部 [root@manager ~]# systemctl restart docker ##三台节点重启docker [root@manager ~]# docker service rm portainer portainer [root@manager ~]# docker service rm portainer_agent portainer_agent
配置私有仓库
创建私有仓库
[root@manager ~]# docker pull httpd
将镜像上传到私有仓库 为镜像打标 [root@manager ~]# docker tag httpd:latest 192.168.10.102:5000/httpd-test:2019-08-25 将镜像上传至私有仓库 [root@manager ~]# docker push 192.168.10.102:5000/httpd-test:2019-08-25 The push refers to repository [192.168.10.102:5000/httpd-test] ##私有仓库 9e0ab3afff15: Pushed 7a0960d9b679: Pushed 8b16516271d6: Pushed 5bcb93651a74: Pushed 1c95c77433e8: Pushed 2019-08-25: digest: sha256:90cca2f9c32ad25afa180da6b14f35de9990cb02b9007350a5bccef4cac1e1c9 size: 1367
创建httpd 的服务测试 (同上)
[root@manager ~]# docker service create --name httpd-test02 --network my-network --publish 8888:80 --replicas=3 192.168.10.102:5000/httpd-test:2019-08-25
wc31arswabmodsxhdqojrlvz9
overall progress: 3 out of 3 tasks
1/3: running
2/3: running
3/3: running
verify: Service converged
可以看到基于私有仓库镜像创建的任务已成功部署 注意:在创建容器时,要改为私有仓库的地址。