docker集群部署portainer


前言

部署单个portainer

docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock --name portainer portainer/portainer

在使用Portainer之前,您需要确保所有节点都安装了Docker Engine,并且已经加入到Docker Swarm集群中。


Docker Swarm集群中创建Portainer

1、创建Docker Swarm集群:使用Docker Swarm init命令在主节点上创建一个Docker Swarm集群,并将其他节点加入到集群中。

例如:

docker swarm init --advertise-addr <主节点IP地址>
docker swarm join --token <令牌> <主节点IP地址>:<端口号>

2、创建一个名为“portainer”网络:使用Docker网络命令创建一个名为“portainer”的Overlay网络。例如:

docker network create -d overlay   --attachable portainer
docker service create \
    --name portainer_agent \
    --network portainer  \
    --mode global \
    --constraint 'node.platform.os == linux' \
    --mount type=bind,src=//var/run/docker.sock,dst=/var/run/docker.sock \
    portainer/agent
mkdir -p  /u01/portainer/data
 docker service create --name portainer --network portainer --publish 9000:9000 --replicas=1  --constraint 'node.role==manager' --container-label com.docker.stack.namespace=portainer --mount type=bind,src=//var/run/docker.sock,dst=/var/run/docker.sock --mount type=bind,src=/u01/portainer/data,dst=/data  portainer/portainer  -H unix:///var/run/docker.sock
或
docker service create \
	--name portainer \
	--network portainer  \
	--publish 9000:9000 \ 
	--replicas=1 \ 
	--constraint 'node.role==manager' \ 
	--constraint node.hostname==h1 \ 
	--container-label com.docker.stack.namespace=portainer \ 
	--mount type=bind,src=//var/run/docker.sock,dst=/var/run/docker.sock \ 
	--mount type=bind,src=/01/portainer/data,dst=/data \ 
	portainer/portainer \ 
	-H unix:///var/run/docker.sock

3、部署Portainer服务:使用Docker Stack命令部署Portainer服务。例如:

docker stack deploy -c <Portainer Compose文件名> --with-registry-auth portainer

portainer的docker-compose文件

version: '3'

services:
  portainer:
    image: portainer/portainer-ce
    command: -H unix:///var/run/docker.sock
    ports:
      - "9000:9000"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /u01/portainer/data:/data
    deploy:
      replicas: 1
      placement:
        constraints: [node.role == manager]

#volumes:
#  portainer_data:

4、查看应用程序状态:使用Docker Stack命令查看您的应用程序在集群中的状态。例如:

docker stack ps portainer

5、访问Portainer:

在浏览器中输入“http://<任一集群节点IP地址>:9000”访问Portainer。然后,您可以使用Portainer的Web界面管理Docker Swarm集群中的容器和服务。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

@王先生1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值