카타코더 Docker - Learn Docker Swarm 101

1 개요[ | ]

카타코더 Docker - Learn Docker Swarm 101
카타코더 Docker Orchestration - Getting Started With Swarm Mode
카타코더 Docker
# 🔗 제목
카타코더 Docker/2 e
🡵 카타코더 Docker - Manage Container Log Files
🡵 카타코더 Docker - Ensuring Container Uptime With Restart Policies
🡵 카타코더 Docker - Adding Docker Metadata & Labels
🡵 카타코더 Docker - Load Balancing Containers
🡵 카타코더 Docker - Orchestration using Docker Compose
🡵 카타코더 Docker - See Container Metrics With Docker Stats
🡵 카타코더 Docker - Creating Optimised Docker Images using Multi-Stage Builds
🡵 카타코더 Docker - Formatting PS Output
🡵 카타코더 Docker - Run Docker From Rootless Users
🡵 카타코더 Docker - Learn Docker Swarm 101
🡵 카타코더 Docker - Docker Swarm Mode Playground

2 Initialise Swarm Mode[ | ]

host01
root@host01:~# docker swarm init
Swarm initialized: current node (75iwe1jhuv7vs4xklwyhrrshq) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-4oc73j12c4b6iie5uerjn7c89d61oj3o81xiz6cojxcwhfkqne-0cwpe2fbjp8nl2hismo98xozx 172.17.0.11:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

3 Join Cluster[ | ]

host02
root@host02:~# token=$(docker -H 172.17.0.11:2345 swarm join-token -q worker)
root@host02:~# echo $token
SWMTKN-1-4oc73j12c4b6iie5uerjn7c89d61oj3o81xiz6cojxcwhfkqne-0cwpe2fbjp8nl2hismo98xozx
root@host02:~# docker swarm join 172.17.0.11:2377 --token $token
This node joined a swarm as a worker.
host01
root@host01:~# docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
75iwe1jhuv7vs4xklwyhrrshq *   host01              Ready               Active              Leader              18.03.0-ce
lsndd2kjwsk88r46st9njinp2     host02              Ready               Active                                  18.03.0-ce

4 Create Overlay Network[ | ]

root@host01:~# docker network create -d overlay skynet
myjvb6abt9zbidsflgehgjzlx

5 Deploy Service[ | ]

root@host01:~# docker service create --name http --network skynet --replicas 2 -p 80:80 katacoda/docker-http-server
rb0owsqpydmbirgrlt3jg4p9u
overall progress: 2 out of 2 tasks
1/2: running   [==================================================>]
2/2: running   [==================================================>]
verify: Service converged
root@host01:~# docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE                                PORTS
rb0owsqpydmb        http                replicated          2/2                 katacoda/docker-http-server:latest   *:80->80/tcp
root@host01:~# docker ps
CONTAINER ID        IMAGE                                COMMAND             CREATED             STATUS              PORTS               NAMES
a79158d3107b        katacoda/docker-http-server:latest   "/app"              28 seconds ago      Up 27 seconds       80/tcp              http.2.widtao6nvdnl79yd8je2ycpww
host02
root@host02:~# docker ps
CONTAINER ID        IMAGE                                COMMAND             CREATED             STATUS              PORTS               NAMES
1fab63d86ae3        katacoda/docker-http-server:latest   "/app"              30 seconds ago      Up 28 seconds       80/tcp              http.1.visivovjplqympsxagqmdosbx
host01
root@host01:~# curl docker
<h1>This request was processed by host: 1fab63d86ae3</h1>
root@host01:~# curl docker
<h1>This request was processed by host: a79158d3107b</h1>

6 Inspect State[ | ]

root@host01:~# docker service ps http
ID                  NAME                IMAGE                                NODE                DESIRED STATE       CURRENT STATE           ERROR               PORTS
visivovjplqy        http.1              katacoda/docker-http-server:latest   host02              Running             Running 2 minutes ago
widtao6nvdnl        http.2              katacoda/docker-http-server:latest   host01              Running             Running 2 minutes ago
root@host01:~# docker service inspect --pretty http

ID:             rb0owsqpydmbirgrlt3jg4p9u
Name:           http
Service Mode:   Replicated
 Replicas:      2
Placement:
UpdateConfig:
 Parallelism:   1
 On failure:    pause
 Monitoring Period: 5s
 Max failure ratio: 0
 Update order:      stop-first
RollbackConfig:
 Parallelism:   1
 On failure:    pause
 Monitoring Period: 5s
 Max failure ratio: 0
 Rollback order:    stop-first
ContainerSpec:
 Image:         katacoda/docker-http-server:latest@sha256:76dc8a47fd019f80f2a3163aba789faf55b41b2fb06397653610c754cb12d3ee
Resources:
Networks: skynet
Endpoint Mode:  vip
Ports:
 PublishedPort = 80
  Protocol = tcp
  TargetPort = 80
  PublishMode = ingress
root@host01:~# docker node ps self
ID                  NAME                IMAGE                                NODE                DESIRED STATE       CURRENT STATE           ERROR               PORTS
widtao6nvdnl        http.2              katacoda/docker-http-server:latest   host01              Running             Running 2 minutes ago
root@host01:~# docker node ps $(docker node ls -q | head -n1)
ID                  NAME                IMAGE                                NODE                DESIRED STATE       CURRENT STATE           ERROR               PORTS
widtao6nvdnl        http.2              katacoda/docker-http-server:latest   host01              Running             Running 3 minutes ago

7 Scale Service[ | ]

oot@host01:~# curl docker
<h1>This request was processed by host: 1fab63d86ae3</h1>
root@host01:~# docker service scale http=5
http scaled to 5
overall progress: 5 out of 5 tasks
1/5: running   [==================================================>]
2/5: running   [==================================================>]
3/5: running   [==================================================>]
4/5: running   [==================================================>]
5/5: running   [==================================================>]
verify: Service converged
root@host01:~# docker ps
CONTAINER ID        IMAGE                                COMMAND             CREATED             STATUS              PORTS               NAMES
befaca1a5de6        katacoda/docker-http-server:latest   "/app"              18 seconds ago      Up 16 seconds       80/tcp              http.5.5uur6hcr6zvmj61gpbep6drjl
a79158d3107b        katacoda/docker-http-server:latest   "/app"              4 minutes ago       Up 4 minutes        80/tcp              http.2.widtao6nvdnl79yd8je2ycpww
root@host01:~# curl docker
<h1>This request was processed by host: a79158d3107b</h1>
root@host01:~# curl docker
<h1>This request was processed by host: 5e90370a147e</h1>
root@host01:~# curl docker
<h1>This request was processed by host: 7cfc96ae8119</h1>
root@host01:~# curl docker
<h1>This request was processed by host: befaca1a5de6</h1>
root@host01:~# curl docker
<h1>This request was processed by host: 1fab63d86ae3</h1>
root@host01:~# curl docker
<h1>This request was processed by host: a79158d3107b</h1>
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}