Last updated 4 years ago
設定虛擬機 hostname
hostnamectl set-hostname [虛擬機名稱]
bash
ifconfig
vim /etc/hosts
192.168.8.129 vm1 192.168.8.130 vm2 192.168.8.131 vm3
check firewall
systemctl status firewalld
getenforce
初始化 docker swarm
docker swarm init --advertise-addr 192.168.8.129
複製到vm2、vm3
vm2
vm3
docker swarm join --token SWMTKN-1-3yzvicajz4c2kyohfzr8zpzuu7jw17jtxz2wf7k2d12nwvq4av-0l3b8c5vwsy12x6m1gupxwuf6 192.168.8.129:2377
docker node ls
docker swarm join-token manager
執行時會顯示 token
docker swarm join --token SWMTKN-1-3yzvicajz4c2kyohfzr8zpzuu7jw17jtxz2wf7k2d12nwvq4av-96ni9b32xo6ngxyscud232nqo 192.168.8.129:2377
將vm2promote 為 manager
docker node promote vm2
離開 swarm
docker swarm leave -f
Update a node
docker node update --availability drain vm1
docker pull dockersamples/visualizer
docker run -itd -p 8888:8080 -e HOST=192.168.8.129 -e PORT=8080 -v /var/run/docker.sock:/var/run/docker.sock --name visualizer dockersamples/visualizer
部署Web服務器服務
docker service create --name myweb -p 8880:80 httpd
docker service ls
兩個容器之間擴展Web服務器服務
docker service scale myweb=5
docker service scale myweb=3
docker node update --availability active vm1
docker service scale myweb=1
docker service ps myweb
docker network ls
docker network inspect [ingress_NetworkID]
docker ps
docker inspect [httpd_容器ID]
移除 service
docker service rm myweb
docker service create --name myweb httpd
更新 service
docker service update --publish-add [8880:80] [myweb]
docker service inspect [serviceID]
查看 service 的 log
docker service logs [serviceID]
docker service logs -f [serviceID]