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集群中的容器和服务。

猜你喜欢

转载自blog.csdn.net/qq_44637753/article/details/129339862
今日推荐