您的位置:首页 > 运维架构 > Docker

docker深入2-UI之portainer的使用简介

2017-08-23 17:09 555 查看
docker深入2-UI之 portainer 的使用简介
2017/9/26

一、前言
预计该 UI 仅满足部分需求,还有坑要填,部分需求得自己去实现。

配置实例
1、配置防火墙
示例:
iptables -A INPUT -s 192.168.200.0/24 -p tcp -m tcp --dport 2375 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 2375 -j DROP

最好是通过安全组之类的来限制,不要暴露到外网,以免未授权访问。

2、调整docker访问,允许内网访问 API 接口
sed -i "/^ExecStart/c ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -H tcp://$(ip a |grep global |grep eth0 |awk '{print $2}' |cut -d'/' -f1):2375" /usr/lib/systemd/system/docker.service
systemctl daemon-reload; systemctl restart docker

3、启动 portainer
首先,引用以下一段话,来表达数据持久化时要考虑的细节: https://docs.docker.com/engine/admin/volumes/bind-mounts/#choosing-the--v-or-mount-flag Differences between -v and --mount behavior
Because the -v and --volume flags have been a part of Docker for a long time, their behavior cannot be changed. This means that there is one behavior that is different between -v and --mount.

If you use -v or --volume to bind-mount a file or directory that does not yet exist on the Docker host, -v will create the endpoint for you. It is always created as a directory.

If you use --mount to bind-mount a file or directory that does not yet exist on the Docker host, Docker does not automatically create it for you, but generates an error.

(本次示例仅在swarm集群的其中一个节点创建该目录即可,这样一来,没有该目录的节点,启动服务时将报错,后续可考虑使用 NFS 之类的共享存储来存放数据。)
# mkdir -p /data/portainer_dev

使用 swarm 集群的方式运行:
# docker service create \
--name portainer_dev \
--detach=true \
--publish 9000:9000 \
--constraint 'node.role == manager' \
--mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
--mount type=bind,src=/data/portainer_dev,dst=/data \
portainer/portainer \
-H unix:///var/run/docker.sock

或直接运行一个容器:
# docker run --restart=unless-stopped -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v /data/portainer_dev:/data --name portainer_dev portainer/portainer -H unix:///var/run/docker.sock

4、请求UI界面 http://node_ip:9000 
设置管理员密码。

二、FAQ
1、在 UI 中 service restart 策略 默认值为 none 的疑惑。
UI创建的 service 在页面显示策略的值为 none 但实际测试发现:

默认策略是:any
[root@test01 ~]# docker service inspect --format '{{ .Spec.TaskTemplate.RestartPolicy.Condition }}' t001
any

且测试集群一个 node 下线后,指定的 service 的副本是否会自动漂移到其他 node 时发现:
命令行得到的的结果,符合预期;
UI 得到的结果,不符合预期;(任务还在已经下线的 node 中显示为 running 状态)

结论: UI 的显示错误。

2、在 UI 页面如何升级 portainer 这个 service 呢?
获取新版本的 digests 串:
]# docker images --digests |grep portainer

例如:
从
sha256:81e216c4b05ab16fbabb69e447fbe0ee408e29cc3aab0404e21e7507d3648df5
升级为:
sha256:c56769dbee09a51af76d7df9fdc5d18411a4328cf1db512416b858a0f831d925

则新的 image 为:
portainer/portainer:latest@sha256:c56769dbee09a51af76d7df9fdc5d18411a4328cf1db512416b858a0f831d925

更新该 service 后刷新下页面即可使用新版本。

3、如何限制 CPU 等资源
请升级到 1.14.1 以后的版本
Add the ability to manage CPU/MEM limits & reservations for Swarm services: #516

4、如何默认不显示所有的容器
请升级到 1.14.1 以后的版本
Persist the status of the show all containers filter: #1198

ZYXW、参考
1、doc https://portainer.readthedocs.io/en/latest/deployment.html 2、github https://github.com/portainer/portainer/releases[/code] 
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  UI docker portainer