您好,登錄后才能下訂單哦!
這篇文章主要介紹了Docker Swarm如何部署,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
軟件 | 版本 |
OS | Ubuntu 16.04.3 LTS |
Docker | 18.03.0-ce |
ubuntu16.04-1 | 172.31.68.241 | swarm manager |
ubuntu16.04-2 | 172.31.68.242 | swarm node |
ubuntu16.04-3 | 172.31.68.243 | swarm node |
docker swarm init --advertise-addr 172.31.68.241
docker swarm join --token SWMTKN-1-1mn8x6itne5ldwad5bmtgtdkemoim3o53dc7u2b5y5zj1lwj4l-etyttp60hpns5i4jifym7y3hd 172.31.68.241:2377
ps:注意要在兩臺worker上都要執行
docker node ls
docker node update --availability drain ubuntu16.04-1
ps:這樣就不會在manager上分配執行任務了
docker node update --label-add app ubuntu16.04-2 docker node update --label-add app ubuntu16.04-3
docker node inspect ubuntu16.04-3
ps:要查看某一項具體的信息,可以使用如下命令模式
docker node inspect ubuntu16.04-3 --format "{{ .Status.Addr }}"
docker service create --replicas 1 -p 4000:80 --name hello 172.31.68.241/library/friendlyhello
docker service ls docker service ps hello
ps:通過service ps可以看到真實的task是運行在ubuntu16.04-2的,容器的名稱叫hello.1。
docker container ls
ps:可以看到在ubuntu16.04-2上,容器的真實名稱是:service名稱+任務id+一串隨機碼。而在ubuntu16.04-3上并無相關task運行,因為replicas為1
docker service inspect hello
[ { "ID": "woxqqkoqr6viu8flojtuuht97", "Version": { "Index": 25 }, "CreatedAt": "2018-08-17T07:20:13.503484813Z", "UpdatedAt": "2018-08-17T07:20:13.515429684Z", "Spec": { "Name": "hello", "Labels": {}, "TaskTemplate": { "ContainerSpec": { "Image": "172.31.68.241/library/friendlyhello:latest@sha256:05def471119a0937508cdcb2445cb55375d15257b0a117e954bcd3527c36eac2", "StopGracePeriod": 10000000000, "DNSConfig": {}, "Isolation": "default" }, "Resources": { "Limits": {}, "Reservations": {} }, "RestartPolicy": { "Condition": "any", "Delay": 5000000000, "MaxAttempts": 0 }, "Placement": { "Platforms": [ { "Architecture": "amd64", "OS": "linux" } ] }, "ForceUpdate": 0, "Runtime": "container" }, "Mode": { "Replicated": { "Replicas": 1 } }, "UpdateConfig": { "Parallelism": 1, "FailureAction": "pause", "Monitor": 5000000000, "MaxFailureRatio": 0, "Order": "stop-first" }, "RollbackConfig": { "Parallelism": 1, "FailureAction": "pause", "Monitor": 5000000000, "MaxFailureRatio": 0, "Order": "stop-first" }, "EndpointSpec": { "Mode": "vip", "Ports": [ { "Protocol": "tcp", "TargetPort": 80, "PublishedPort": 4000, "PublishMode": "ingress" } ] } }, "Endpoint": { "Spec": { "Mode": "vip", "Ports": [ { "Protocol": "tcp", "TargetPort": 80, "PublishedPort": 4000, "PublishMode": "ingress" } ] }, "Ports": [ { "Protocol": "tcp", "TargetPort": 80, "PublishedPort": 4000, "PublishMode": "ingress" } ], "VirtualIPs": [ { "NetworkID": "zhamhv5cl7zhr7c7g6n1so6kv", "Addr": "10.255.0.5/16" } ] } } ]
curl http://172.31.68.241:4000 -I curl http://172.31.68.242:4000 -I curl http://172.31.68.243:4000 -I
ps:隨便訪問swarm mode集群內的任何一個節點,都可以正常訪問該服務。
docker service scale hello=2
docker service ps hello
docker config create hello-config ./hello-config
docker config ls
docker config inspect hello-config
docker service create --replicas 1 --name config-test --config source=hello-config,target=/mnt/hello-config 172.31.68.241/library/friendlyhello
docker service ps config-test
docker container ls docker container exec -it b06c415e7cac /bin/bash
ps:如果在啟動service的時候不指定config的source/target,則默認config在容器內的掛載目錄在/hello-config
config一般在容器所在宿主機的/var/lib/docker/containers/container_id/mounts/secrets目錄下面,是一個隨機字符串文件
config和secret的差別就是一個是本地文件,一個是在tmpfs中存儲的
#查看secretr文件 cat hello-config-secret #創建secret docker secret create hello-secret ./hello-config-secret #查看secret docker secret ls
#啟動服務 docker service create --replicas 1 --label app --secret hello-secret --name secret-test 172.31.68.241/library/friendlyhello #查看task在哪臺機器運行 docker service ps secret-test
docker container exec -it 47c8f6f74ae3 /bin/bash
ps:在使用secret的時候,secret配置一般在/run/secrets/目錄下面,名稱就是secret名稱
感謝你能夠認真閱讀完這篇文章,希望小編分享的“Docker Swarm如何部署”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關注億速云行業資訊頻道,更多相關知識等著你來學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。