본문 바로가기
Study/Devops

[Docker swarm] 활용해보기 with AWS

by 리노 Linho 2022. 11. 24.

시작하며

AWS Instance information

  • type: t2.micro
  • size: 3 node ( master, worker1, worker2 )
  • os: ubuntu 20.04

AWS Instance Network information

  • master instance
    • public ip: 13.209.5.232
    • private ip: 172.31.32.34
  • worker1 instance
    • public ip: 15.165.159.52
    • private ip: 172.31.36.212
  • worker2 instance
    • public ip:13.209.67.244
    • private ip: 172.31.47.47

AWS security group

기본적으로 보안 설정에 맞게 세팅해야하지만 테스트를 위해 모든 보안포트를 오픈

Docker 설치

명령어

$ sudo apt-get update
$ sudo apt-get install \
      ca-certificates \
      curl \
      gnupg \
      lsb-release

결과

$ sudo apt-get install \
>     ca-certificates \
>     curl \
>     gnupg \
>     lsb-release
Reading package lists... Done
Building dependency tree       
Reading state information... Done
lsb-release is already the newest version (11.1.0ubuntu2).
lsb-release set to manually installed.
ca-certificates is already the newest version (20211016~20.04.1).
ca-certificates set to manually installed.
gnupg is already the newest version (2.2.19-3ubuntu2.2).
gnupg set to manually installed.
The following additional packages will be installed:
  libcurl4
The following packages will be upgraded:
  curl libcurl4
2 upgraded, 0 newly installed, 0 to remove and 64 not upgraded.
Need to get 396 kB of archives.
After this operation, 2048 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu focal-updates/main amd64 curl amd64 7.68.0-1ubuntu2.14 [161 kB]
Get:2 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu focal-updates/main amd64 libcurl4 amd64 7.68.0-1ubuntu2.14 [235 kB]
Fetched 396 kB in 0s (11.8 MB/s)
(Reading database ... 61718 files and directories currently installed.)
Preparing to unpack .../curl_7.68.0-1ubuntu2.14_amd64.deb ...
Unpacking curl (7.68.0-1ubuntu2.14) over (7.68.0-1ubuntu2.13) ...
Preparing to unpack .../libcurl4_7.68.0-1ubuntu2.14_amd64.deb ...
Unpacking libcurl4:amd64 (7.68.0-1ubuntu2.14) over (7.68.0-1ubuntu2.13) ...
Setting up libcurl4:amd64 (7.68.0-1ubuntu2.14) ...
Setting up curl (7.68.0-1ubuntu2.14) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...
ubuntu@ip-172-31-32-34:~$ sudo apt-get install     ca-certificates     curl     gnupg     lsb-release
Reading package lists... Done
Building dependency tree       
Reading state information... Done
lsb-release is already the newest version (11.1.0ubuntu2).
ca-certificates is already the newest version (20211016~20.04.1).
curl is already the newest version (7.68.0-1ubuntu2.14).
gnupg is already the newest version (2.2.19-3ubuntu2.2).
0 upgraded, 0 newly installed, 0 to remove and 64 not upgraded.

명령어

$ sudo mkdir -p /etc/apt/keyrings
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
$ sudo apt-get update

결과

$ sudo apt-get update
Hit:1 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu focal-updates InRelease      
Hit:3 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu focal-backports InRelease    
Get:4 https://download.docker.com/linux/ubuntu focal InRelease [57.7 kB]               
Get:5 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages [20.9 kB]   
Get:6 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]                
Fetched 192 kB in 2s (127 kB/s)                        
Reading package lists... Done

명령어

$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

결과

$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  docker-ce-rootless-extras docker-scan-plugin pigz slirp4netns
Suggested packages:
  aufs-tools cgroupfs-mount | cgroup-lite
The following NEW packages will be installed:
  containerd.io docker-ce docker-ce-cli docker-ce-rootless-extras docker-compose-plugin docker-scan-plugin pigz slirp4netns
0 upgraded, 8 newly installed, 0 to remove and 64 not upgraded.
Need to get 111 MB of archives.
After this operation, 428 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu focal/universe amd64 pigz amd64 2.4-1 [57.4 kB]
Get:2 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu focal/universe amd64 slirp4netns amd64 0.4.3-1 [74.3 kB]
Get:3 https://download.docker.com/linux/ubuntu focal/stable amd64 containerd.io amd64 1.6.10-1 [27.7 MB]
Get:4 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce-cli amd64 5:20.10.21~3-0~ubuntu-focal [41.5 MB]
Get:5 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce amd64 5:20.10.21~3-0~ubuntu-focal [20.5 MB]
Get:6 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce-rootless-extras amd64 5:20.10.21~3-0~ubuntu-focal [8394 kB]
Get:7 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-compose-plugin amd64 2.12.2~ubuntu-focal [9567 kB]
Get:8 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-scan-plugin amd64 0.21.0~ubuntu-focal [3622 kB]
Fetched 111 MB in 2s (61.5 MB/s)         
Selecting previously unselected package pigz.
(Reading database ... 61718 files and directories currently installed.)
Preparing to unpack .../0-pigz_2.4-1_amd64.deb ...
Unpacking pigz (2.4-1) ...
Selecting previously unselected package containerd.io.
Preparing to unpack .../1-containerd.io_1.6.10-1_amd64.deb ...
Unpacking containerd.io (1.6.10-1) ...
Selecting previously unselected package docker-ce-cli.
Preparing to unpack .../2-docker-ce-cli_5%3a20.10.21~3-0~ubuntu-focal_amd64.deb ...
Unpacking docker-ce-cli (5:20.10.21~3-0~ubuntu-focal) ...
Selecting previously unselected package docker-ce.
Preparing to unpack .../3-docker-ce_5%3a20.10.21~3-0~ubuntu-focal_amd64.deb ...
Unpacking docker-ce (5:20.10.21~3-0~ubuntu-focal) ...
Selecting previously unselected package docker-ce-rootless-extras.
Preparing to unpack .../4-docker-ce-rootless-extras_5%3a20.10.21~3-0~ubuntu-focal_amd64.deb ...
Unpacking docker-ce-rootless-extras (5:20.10.21~3-0~ubuntu-focal) ...
Selecting previously unselected package docker-compose-plugin.
Preparing to unpack .../5-docker-compose-plugin_2.12.2~ubuntu-focal_amd64.deb ...
Unpacking docker-compose-plugin (2.12.2~ubuntu-focal) ...
Selecting previously unselected package docker-scan-plugin.
Preparing to unpack .../6-docker-scan-plugin_0.21.0~ubuntu-focal_amd64.deb ...
Unpacking docker-scan-plugin (0.21.0~ubuntu-focal) ...
Selecting previously unselected package slirp4netns.
Preparing to unpack .../7-slirp4netns_0.4.3-1_amd64.deb ...
Unpacking slirp4netns (0.4.3-1) ...
Setting up slirp4netns (0.4.3-1) ...
Setting up docker-scan-plugin (0.21.0~ubuntu-focal) ...
Setting up containerd.io (1.6.10-1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service.
Setting up docker-compose-plugin (2.12.2~ubuntu-focal) ...
Setting up docker-ce-cli (5:20.10.21~3-0~ubuntu-focal) ...
Setting up pigz (2.4-1) ...
Setting up docker-ce-rootless-extras (5:20.10.21~3-0~ubuntu-focal) ...
Setting up docker-ce (5:20.10.21~3-0~ubuntu-focal) ...
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for systemd (245.4-4ubuntu3.17) ...

도커 설치 완료

도커 스웜 설정

마스터 노드 설정

명령어

$ sudo docker swarm init --advertise-addr 마스터노드 IP

결과

$ sudo docker swarm init --advertise-addr 13.209.5.232
Swarm initialized: current node (g1qomwugw3e8bcryjdpfext7g) is now a manager.

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

    docker swarm join --token SWMTKN-1-212cwvdhs276cnspnyif27hj6tkqwlfppuear0ftx2ylrufcr2-eqjv2x4ikn4blm9fcme7aumcw 13.209.5.232:2377

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

워커 노드 설정

마스터 노드로부터 나온 토큰을 워커노드 두개에 입력한다

명령어

$ sudo docker swarm join --token 마스터 노드로부터 발급 받은 토큰

결과

$ sudo docker swarm join --token SWMTKN-1-212cwvdhs276cnspnyif27hj6tkqwlfppuear0ftx2ylrufcr2-eqjv2x4ikn4blm9fcme7aumcw 13.209.5.232:2377
This node joined a swarm as a worker.

추가

토큰을 재발급 받고 싶을 때 사용하는 명령어

docker swarm join-token --rotate manager

마스터 노드와 연결된 워커노드

명령어

$ sudo docker node ls

결과

$ sudo docker node ls
ID                            HOSTNAME           STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
g1qomwugw3e8bcryjdpfext7g *   ip-172-31-32-34    Ready     Active         Leader           20.10.21
l8w22rjxvbdoaiyj5k9ybobtv     ip-172-31-36-212   Ready     Active                          20.10.21
rpijguq53l3pvqv6h48w9u1n6     ip-172-31-47-47    Ready     Active                          20.10.21

도커 스웜 테스트

샘플 코드 실행

반복적으로 hello world를 출력하는 단순 코드

명령어

$ sudo docker service create ubuntu:18.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"

결과

$ sudo docker service create ubuntu:18.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"
l3szfp6y2z4ynj2fuutyydldd
overall progress: 1 out of 1 tasks 
1/1: running   [==================================================>] 
verify: Service converged 

실행 중인 서비스 확인

명령어

$ sudo docker service ls
$ sudo docker service ps 서비스명
$ sudo docker service rm 서비스명

결과

$ sudo docker service ls 
ID             NAME       MODE         REPLICAS   IMAGE          PORTS
l3szfp6y2z4y   sweet_wu   replicated   1/1        ubuntu:18.04   
$ sudo docker service ps sweet_wu
ID             NAME         IMAGE          NODE              DESIRED STATE   CURRENT STATE           ERROR     PORTS
n6oe7wu49be6   sweet_wu.1   ubuntu:18.04   ip-172-31-32-34   Running         Running 8 minutes ago             
$ sudo docker service rm sweet_wu
sweet_wu
$ sudo docker service ls
ID        NAME      MODE      REPLICAS   IMAGE     PORTS

서비스 다수 실행

이름, 컨테이너수, 포트를 명령어를 통해 설정할 수 있음

명령어

$ sudo docker service create --name 서비스명 --replicas 컨테이너수 -p 내부포트:외부포트 도커이미지정보
$ sudo docker service ps 서비스명

결과

$ sudo docker service create --name myweb --replicas 2 -p 80:80 nginx  
6tdum7rcig32dfj7t6j3yq5j0  
overall progress: 2 out of 2 tasks   
1/2: running   [==================================================>]   
2/2: running   [==================================================>]   
verify: Service converged   
$ sudo docker service ps myweb  
ID             NAME      IMAGE          NODE               DESIRED STATE   CURRENT STATE           ERROR     PORTS  
e9khllq0ep04   myweb.1   nginx:latest   ip-172-31-36-212   Running         Running 3 minutes ago               
g1szh8j72n72   myweb.2   nginx:latest   ip-172-31-32-34    Running         Running 3 minutes ago

도커스웜 네트워크

Ingress 네트워크는 어떤 노드로 접근해도 특정 서비스의 컨테이너 접근 가능하며 로드밸런싱 / 라우팅 메쉬(mesh) 기능을 포함

명령어

$ sudo docker network ls  
$ sudo docker network ls | grep ingress  
$ sudo docker service create --name whoami -p 4567:4567 subicura/whoami:1  
$ sudo docker service ls  
$ sudo docker service ps whoami

결과

$ sudo docker network ls  
NETWORK ID     NAME              DRIVER    SCOPE  
833b5a0051f8   bridge            bridge    local  
115b1cb00962   docker_gwbridge   bridge    local  
68eb839b2047   host              host      local  
sn9c33a4culz   ingress           overlay   swarm  
30a565308637   none              null      local  
$ sudo docker network ls | grep ingress  
sn9c33a4culz   ingress           overlay   swarm  
$ sudo docker service create --name whoami -p 4567:4567 subicura/whoami:1  
hxjf9c2o1t0ou2yayvj7zph4j  
overall progress: 1 out of 1 tasks   
1/1: running   [==================================================>]   
verify: Service converged   
$ sudo docker service ls  
ID             NAME      MODE         REPLICAS   IMAGE               PORTS  
6tdum7rcig32   myweb     replicated   2/2        nginx:latest        *:80->80/tcp  
hxjf9c2o1t0o   whoami    replicated   1/1        subicura/whoami:1   *:4567->4567/tcp  
$ sudo docker service ps whoami  
ID             NAME       IMAGE               NODE              DESIRED STATE   CURRENT STATE            ERROR     PORTS  
ryyvwfls3mxk   whoami.1   subicura/whoami:1   ip-172-31-47-47   Running         Running 23 seconds ago

도커 스웜 스케일링

명령어

$ sudo docker service ls  
$ sudo docker service scale myweb=4  
$ sudo docker service ps myweb  
$ sudo docker service scale myweb=1  
$ sudo docker service ps myweb

결과

$ sudo docker service ls  
ID             NAME      MODE         REPLICAS   IMAGE               PORTS  
6tdum7rcig32   myweb     replicated   2/2        nginx:latest        *:80->80/tcp  
hxjf9c2o1t0o   whoami    replicated   1/1        subicura/whoami:1   *:4567->4567/tcp  
$ sudo docker service scale myweb=4  
myweb scaled to 4  
overall progress: 4 out of 4 tasks   
1/4: running   [==================================================>]   
2/4: running   [==================================================>]   
3/4: running   [==================================================>]   
4/4: running   [==================================================>]   
verify: Service converged   
$ sudo docker service ps myweb  
ID             NAME      IMAGE          NODE               DESIRED STATE   CURRENT STATE            ERROR     PORTS  
e9khllq0ep04   myweb.1   nginx:latest   ip-172-31-36-212   Running         Running 22 minutes ago               
g1szh8j72n72   myweb.2   nginx:latest   ip-172-31-32-34    Running         Running 22 minutes ago               
hdcddwjdogn0   myweb.3   nginx:latest   ip-172-31-47-47    Running         Running 27 seconds ago               
ssddcpjaihi4   myweb.4   nginx:latest   ip-172-31-36-212   Running         Running 35 seconds ago               
$ sudo docker service scale myweb=1  
myweb scaled to 1  
overall progress: 1 out of 1 tasks   
1/1: running   [==================================================>]   
verify: Service converged   
$ sudo docker service ps myweb  
ID             NAME      IMAGE          NODE               DESIRED STATE   CURRENT STATE            ERROR     PORTS  
e9khllq0ep04   myweb.1   nginx:latest   ip-172-31-36-212   Running         Running 22 minutes ago

도커 스웜 글로벌 서비스모드

  • 노드별로 하나 이상 생성
  • replicas 수를 별도로 지정하지 않음
  • 모니터링 노드 생성할 때 유용

명령어


$ sudo docker service ls  
$ sudo docker service create --name 서비스명 --mode global 도커이미지  
$ sudo docker service ps global_web  

결과

$ sudo docker service ls
ID             NAME      MODE         REPLICAS   IMAGE               PORTS
6tdum7rcig32   myweb     replicated   1/1        nginx:latest        *:80->80/tcp
hxjf9c2o1t0o   whoami    replicated   1/1        subicura/whoami:1   *:4567->4567/tcp
$ sudo docker service create --name global_web --mode global nginx
dowjukeq726acp9yelft0s1wu
overall progress: 3 out of 3 tasks 
l8w22rjxvbdo: running   [==================================================>] 
rpijguq53l3p: running   [==================================================>] 
g1qomwugw3e8: running   [==================================================>] 
verify: Service converged 
$ sudo docker service ls
ID             NAME         MODE         REPLICAS   IMAGE               PORTS
dowjukeq726a   global_web   global       3/3        nginx:latest        
6tdum7rcig32   myweb        replicated   1/1        nginx:latest        *:80->80/tcp
hxjf9c2o1t0o   whoami       replicated   1/1        subicura/whoami:1   *:4567->4567/tcp
$ sudo docker service ps global_web
ID             NAME                                   IMAGE          NODE               DESIRED STATE   CURRENT STATE            ERROR     PORTS
t321rl0vklif   global_web.g1qomwugw3e8bcryjdpfext7g   nginx:latest   ip-172-31-32-34    Running         Running 17 seconds ago             
45khnprhx6le   global_web.l8w22rjxvbdoaiyj5k9ybobtv   nginx:latest   ip-172-31-36-212   Running         Running 17 seconds ago             
kx6omnwntxiu   global_web.rpijguq53l3pvqv6h48w9u1n6   nginx:latest   ip-172-31-47-47    Running         Running 17 seconds ago       

도커 스웜 서비스 업데이트

명령어

$ sudo docker service ls
$ sudo docker service create --name 서비스명 --replicas 컨테이너수 도커이미지명:버전
$ sudo docker service update --image 도커이미지명:버전 서비스명
$ sudo docker service ps 서비스명

결과

$ sudo docker service ls
ID             NAME         MODE         REPLICAS   IMAGE               PORTS
dowjukeq726a   global_web   global       3/3        nginx:latest        
6tdum7rcig32   myweb        replicated   1/1        nginx:latest        *:80->80/tcp
hxjf9c2o1t0o   whoami       replicated   1/1        subicura/whoami:1   *:4567->4567/tcp
$ sudo docker service create --name myweb2 --replicas 3 nginx:1.10
qd1eu3tjjdjf45acogt2h6ar9
overall progress: 3 out of 3 tasks 
1/3: running   [==================================================>] 
2/3: running   [==================================================>] 
3/3: running   [==================================================>] 
verify: Service converged 
$ sudo docker service ls
ID             NAME         MODE         REPLICAS   IMAGE               PORTS
dowjukeq726a   global_web   global       3/3        nginx:latest        
6tdum7rcig32   myweb        replicated   1/1        nginx:latest        *:80->80/tcp
qd1eu3tjjdjf   myweb2       replicated   3/3        nginx:1.10          
hxjf9c2o1t0o   whoami       replicated   1/1        subicura/whoami:1   *:4567->4567/tcp
$ sudo docker service update --image nginx:1.11 myweb2
myweb2
overall progress: 3 out of 3 tasks 
1/3: running   [==================================================>] 
2/3: running   [==================================================>] 
3/3: running   [==================================================>] 
verify: Service converged 
$ sudo docker service ps myweb2
ID             NAME           IMAGE        NODE               DESIRED STATE   CURRENT STATE             ERROR     PORTS
ow32n29nnnkd   myweb2.1       nginx:1.11   ip-172-31-32-34    Running         Running 27 seconds ago              
rch4jxuosu2y    \_ myweb2.1   nginx:1.10   ip-172-31-32-34    Shutdown        Shutdown 32 seconds ago             
jvl24bg33v97   myweb2.2       nginx:1.11   ip-172-31-47-47    Running         Running 22 seconds ago              
gmxnndcmctco    \_ myweb2.2   nginx:1.10   ip-172-31-47-47    Shutdown        Shutdown 25 seconds ago             
s6z5x7tmcksc   myweb2.3       nginx:1.11   ip-172-31-36-212   Running         Running 33 seconds ago              
pqn55zy7jew0    \_ myweb2.3   nginx:1.10   ip-172-31-36-212   Shutdown        Shutdown 37 seconds ago

도커 롤링 업데이트

명령어

$ sudo docker service create --replicas 컨테이너수 --name 서비스명 --update-delay 시간 --update-parallelism 개수 도커이미지:버전
$ sudo docker service inspect --pretty 서비스명

결과

$ sudo docker service create --replicas 4 --name myweb3 --update-delay 10s --update-parallelism 2 nginx:1.10
79afuzkpcjtqdvduh7ett1hvs
overall progress: 4 out of 4 tasks 
1/4: running   [==================================================>] 
2/4: running   [==================================================>] 
3/4: running   [==================================================>] 
4/4: running   [==================================================>] 
verify: Service converged 
$ sudo docker service inspect --pretty myweb3

ID:             79afuzkpcjtqdvduh7ett1hvs
Name:           myweb3
Service Mode:   Replicated
 Replicas:      4
Placement:
UpdateConfig:
 Parallelism:   2
 Delay:         10s
 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:         nginx:1.10@sha256:6202beb06ea61f44179e02ca965e8e13b961d12640101fca213efbfd145d7575
 Init:          false
Resources:
Endpoint Mode:  vip

도커 스웜 서비스 로그

명령어

$ sudo docker service ls
$ sudo docker service logs 서비스명

결과

$ sudo docker service ls
ID             NAME         MODE         REPLICAS   IMAGE               PORTS
dowjukeq726a   global_web   global       3/3        nginx:latest        
6tdum7rcig32   myweb        replicated   1/1        nginx:latest        *:80->80/tcp
qd1eu3tjjdjf   myweb2       replicated   3/3        nginx:1.11          
79afuzkpcjtq   myweb3       replicated   4/4        nginx:1.10          
hxjf9c2o1t0o   whoami       replicated   1/1        subicura/whoami:1   *:4567->4567/tcp
$ sudo docker service logs whoami
whoami.1.ryyvwfls3mxk@ip-172-31-47-47    | [2022-11-23 05:43:35] INFO  WEBrick 1.3.1
whoami.1.ryyvwfls3mxk@ip-172-31-47-47    | [2022-11-23 05:43:35] INFO  ruby 2.3.3 (2016-11-21) [x86_64-linux]
whoami.1.ryyvwfls3mxk@ip-172-31-47-47    | == Sinatra (v1.4.7) has taken the stage on 4567 for development with backup from WEBrick
whoami.1.ryyvwfls3mxk@ip-172-31-47-47    | [2022-11-23 05:43:35] INFO  WEBrick::HTTPServer#start: pid=7 port=4567

도커 스웜 서비스 종료

명령어

$ sudo docker service rm 서비스명

결과

ubuntu@ip-172-31-32-34:~$ sudo docker service ls
ID             NAME         MODE         REPLICAS   IMAGE               PORTS
dowjukeq726a   global_web   global       3/3        nginx:latest        
6tdum7rcig32   myweb        replicated   1/1        nginx:latest        *:80->80/tcp
qd1eu3tjjdjf   myweb2       replicated   3/3        nginx:1.11          
79afuzkpcjtq   myweb3       replicated   4/4        nginx:1.10          
hxjf9c2o1t0o   whoami       replicated   1/1        subicura/whoami:1   *:4567->4567/tcp
ubuntu@ip-172-31-32-34:~$ sudo docker service rm global_web
global_web
ubuntu@ip-172-31-32-34:~$ sudo docker service rm myweb
myweb
ubuntu@ip-172-31-32-34:~$ sudo docker service rm myweb3
myweb3
ubuntu@ip-172-31-32-34:~$ sudo docker service rm whoami
whoami