记录一个swarm部署portainer的方式
编写yml
bash
version: '3.2'
services:
agent:
image: portainer/agent:2.0.0
volumes:
- /var/run/docker.sock:/var/run/docker.sock # 替换为自己docker的sock文件路径
- /applications/docker/volumes:/var/lib/docker/volumes # 替换为自己docker的挂载目录
networks:
- agent_network
deploy:
mode: global
placement:
constraints: [node.platform.os == linux]
portainer:
image: portainer/portainer-ce:2.0.0
command: -H tcp://tasks.agent:9001 --tlsskipverify
ports:
- "8006:9000"
- "8008:8000"
volumes:
- portainer_data:/data
networks:
- agent_network
deploy:
mode: replicated
replicas: 1
placement:
constraints: [node.role == manager]
networks:
agent_network:
driver: overlay
attachable: true
volumes:
portainer_data:
启动
bash
# 这里用了docker 的 volumes功能,但其实也可以直接挂载一个目录,和普通的服务挂载目录一样用
docker volume create portainer_data
# 启动
docker stack deploy --with-registry-auth --prune -c portainer-agent-stack.yml portainer
访问ip:8006 # 9000映射的端口访问即可
另外:docker run方式也记录一个
bash
docker run -itd -p 8006:9000 -p 8008:8000 --name portainer \
--restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /portainer_data:/data \ # 这里就是自己任意挂载一个目录
portainer/portainer