Portainer是一个可视化的容器镜像的图形管理工具,利用Portainer可以轻松构建,管理和维护Docker环境。 而且完全免费,基于容器化的安装方式,方便高效部署。
Portainer安装
版本选择,portainer从2.0.0版本镜像名字改为portainer/portainer-ce,建议安装最新版本镜像。
#拉取镜像
docker pull portainer/portainer-ce:latest
#启动容器
docker run -d --name portainer -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v /app/portainer_data:/data --restart always --privileged=true portainer/portainer-ce:latest
安装非常简单,然后访问 http://192.168.2.100:9000/
初次安装后登陆需要配置账号密码。
功能这不再一一啰嗦了,直接上干货,自己目前在使用过程中遇到的问题。
Swarm
Docker Swarm 和 Docker Compose 一样,都是 Docker 官方容器编排项目,但不同的是,Docker Compose 是一个在单个服务器或主机上创建多个容器的工具,而 Docker Swarm 则可以在多个服务器或主机上创建容器集群服务,对于微服务的部署,显然 Docker Swarm 会更加适合。
Node Status Down
节点一直处于Down Status
尝试重启该节点的Docker,但是无效。然后从Swarm集群中移除该节点,再次Join到集群,解决问题。
#从master node 移除节点
docker node rm [ID]
#在node节点join集群
docker swarm join --token [TOKEN] [master node ip]:2377
Node Label
swarm 集群节点标签,用于容器部署的时候,根据Label部署到指定的服务器上。
另一篇文章,详细写了Label的使用:东小西:Node Label节点标签与服务约束
docker node update --label-add role=base kvm-10-115-80-116
Services & Stacks
在开发过程中,遇到的任何问题,大家都可以先从官方的Docker Docs寻找答案,切勿直接采用度娘的博客的答案,Docker Docs,真的YYDS!!!!
下面通过Service和Stack两种方式部署服务
Service
docker service create --name test-service \
--mount type=volume,source=service-logs,destination=/app/logs \
--network host \
-e TZ="Asia/Shanghai" \
-e SPRING.PROFILES.ACTIVE=dev \
-e LOG.HOME=/app/logs \
--mode replicated \
--replicas 2 \
--replicas-max-per-node=1 \
--constraint 'node.labels.role == service' \
192.168.2.100:5000/test-service:latest
- --mount: 挂载Voluem。type有volume,bind,tmpfs, ornpipe,常用的是volume和bind。需要注意的type=bind的时候,宿主机必须存在挂载目录。
- --network:当前使用Host模式,采用宿主机网络。
- --mode:部署模式 (replicated or global)(默认"replicated"),global模式会在可部署的节点有且仅部署一个容器。
- -e:环境变量,比如说时区,springboot配置参数等。
- --replicas:副本数。
- --replicas-max-per-node :每个节点的最大任务数(默认值0=无限制)
- --constraint:放置约束,根据Label部署到指定的服务器上。
在部署过程中,发现页面没有可以配置--replicas-max-per-node=1的地方,不知道咋搞......
Stack
docker-compose.yml编写过程中,有任何的问题,可以查看官方Docker Docs
version: "3.8"
services:
test-service:
image: 192.168.2.100:5000/test-service:latest
volumes:
- type: volume
source: service-logs
target: /app/logs
networks:
- hostnet
environment:
- TZ=Asia/Shanghai
- SPRING.PROFILES.ACTIVE=dev
- LOG.HOME=/app/logs
deploy:
replicas: 2
mode: Replicated
placement:
max_replicas_per_node: 1
constraints:
- node.labels.role==service
update_config:
parallelism: 1
delay: 5s
restart_policy:
condition: on-failure
networks:
hostnet:
external: true
name: host
volumes:
service-logs:
在portainer页面编辑docker-compose.yml,遇到的几个小问题。
Deployment error unsupported Compose file version:3.8
- Docker版本问题:将docker和docker-compose版本升级到最近的一些版本。
- Portainer版本问题:发现自己的Docker版本是 20.10.12,但是安装的Portainer版本是1.3.2,尝试将Portainer版本升级到2.11.0,解决问题。
版本对照关系
Deployment error max_replicas_per_node Additional property max_replicas_per_node is not allowed
- 期初docker-compose.yml中写的version:3.7
- 在官方Docs中找到原因,还是版本的问题,max_replicas_per_node 是在Version 3.8后加入的。
Version 3.8
An upgrade of version 3 that introduces new parameters. It is only available with Docker Engine version 19.03.0 and higher.
Introduces the following additional parameters:
- max_replicas_per_node in placement configurations
- template_driver option for config and secret configurations. This option is only supported when deploying swarm services using docker stack deploy.
- driver and driver_opts option for secret configurations. This option is only supported when deploying swarm services using docker stack deploy.
以上是近期接触Docker portainer遇到的问题,可能很傻,但是很值得。
第一次接触新的方向,遇到问题尝试多次无果后,升级至最新版本也是一种解决方案。
最后强调
Docker Docs 真的YYDS!!!!
Docker Docs 真的YYDS!!!!
Docker Docs 真的YYDS!!!!