도커 클러스터 배포 포터이너


머리말

단일 포터이너 배포

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

Portainer를 사용하기 전에 모든 노드에 Docker 엔진이 설치되어 있고 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 network 명령을 사용하여 "portainer"라는 오버레이 네트워크를 생성합니다. 예를 들어:

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의 웹 인터페이스를 사용하여 Docker Swarm 클러스터에서 컨테이너 및 서비스를 관리할 수 있습니다.

추천

출처blog.csdn.net/qq_44637753/article/details/129339862