參考的官網地址為:https://portainer.readthedocs.io/en/stable/deployment.html
先更新Centos docker 鏡像加速地址:
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://ef017c13.m.daocloud.io
新建一個卷(portainer_data)來存Portainer數據
docker volume create portainer_data
docker run -d -p 9000:9000 -p 8000:8000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
修改將要被遠程連接的客戶機的docker.service 文件開通docker的遠程管理:
vim /lib/systemd/system/docker.service ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375
重啟客戶機docker
systemctl daemon-reload
systemctl restart docker
關閉客戶機防火牆
查看防火牆狀態: systemctl status firewalld.service #綠的running表示防火牆開啟
執行關閉命令: systemctl stop firewalld.service
再次執行查看防火牆命令:systemctl status firewalld.service
執行開機禁用防火牆自啟命令 : systemctl disable firewalld.service
不建議修改daemon.json,
vim /etc/docker/daemon.json { "registry-mirrors": ["https://registry.docker-cn.com"], "insecure-registries": ["rep.dhis2.org.cn"], # 大坑!不能在這允許DOCKER的TCP通迅,重啟不了(CentOS 7,Dokcer 19.03.1): "hosts": ["tcp://0.0.0.0:2375","unix:///var/run/docker.sock"] }
如果docker加入了swarm集群,則建議通過代理統一管理。在Swarm管理節點執行以下語句,然后即可通過代理連接客戶機了
$ curl -L https://downloads.portainer.io/portainer-agent-stack.yml -o portainer-agent-stack.yml $ docker stack deploy --compose-file=portainer-agent-stack.yml portainer