[Docker] 도커 컴포즈

gununoo·2022년 8월 22일
4

Docker

목록 보기
4/8
post-thumbnail

실습 1 - 도커 네트워크 구성

  • yaml 파일 작성
rapa@rapa:~/0822$ vi docker-compose.yml 
version: '3.7'

services:
  web: 
    image: httpd
    ports:
      - "8001:80" 
    command: httpd -D FOREGROUND  
    depends_on: 
      - db
    links:
      - db:mysql 

  db: 
    image: mysql:5.7
    environment: 
      - MYSQL_ROOT_PASSWORD=test123
      - MYSQL_DATABASE=testdb
  • 배포
rapa@rapa:~/0822$ dc up -d 
Creating network "0822_default" with the default driver
Creating 0822_db_1 ... done
Creating 0822_web_1 ... done

-> -d: 백그라운드에서 돌릴 것임
-> 자동으로 별도의 네트워크가 만들어짐(0822_default). 디렉토리의 이름이 앞에 붙음.
-> 별도의 네트워크를 위한 기본 네트워크가 생성되고 컨테이너도 생성된다.

  • 생성 확인
rapa@rapa:~/0822$ dc ps
   Name                Command             State                  Ports                
---------------------------------------------------------------------------------------
0822_db_1    docker-entrypoint.sh mysqld   Up      3306/tcp, 33060/tcp                 
0822_web_1   httpd -D FOREGROUND           Up      0.0.0.0:8001->80/tcp,:::8001->80/tcp

-> docker-compose로 만든 컨테이너만을 확인한다.

  • scale 시도해보기
rapa@rapa:~/0822$ dc scale web=2 
WARNING: The scale command is deprecated. Use the up command with the --scale flag instead.
WARNING: The "web" service specifies a port on the host. If multiple containers for this service are created on a single host, the port will clash.
Creating 0822_web_2 ... 
Creating 0822_web_2 ... error

ERROR: for 0822_web_2  Cannot start service web: driver failed programming external connectivity on endpoint 0822_web_2 (6aae683dd62882304babb810746ad7f667e36f61d9ffe10a05564fb30dfb4bee): Bind for 0.0.0.0:8001 failed: port is already allocated
ERROR: Cannot start service web: driver failed programming external connectivity on endpoint 0822_web_2 (6aae683dd62882304babb810746ad7f667e36f61d9ffe10a05564fb30dfb4bee): Bind for 0.0.0.0:8001 failed: port is already allocated

-> 8001번 포트가 중복되기 때문에 오류 발생

  • yaml 파일 수정
rapa@rapa:~/0822$ vi docker-compose.yml 
  • 포트의 범위를 줌
    ports:
      - "8001-8002:80"
  • 다시 scale 시도
rapa@rapa:~/0822$ dc scale web=2 
WARNING: The scale command is deprecated. Use the up command with the --scale flag instead.
WARNING: The "web" service specifies a port on the host. If multiple containers for this service are created on a single host, the port will clash.
Creating 0822_web_2 ... done
  • 생성 확인
rapa@rapa:~/0822$ dc ps
   Name                Command             State                  Ports                
---------------------------------------------------------------------------------------
0822_db_1    docker-entrypoint.sh mysqld   Up      3306/tcp, 33060/tcp                 
0822_web_1   httpd -D FOREGROUND           Up      0.0.0.0:8001->80/tcp,:::8001->80/tcp
0822_web_2   httpd -D FOREGROUND           Up      0.0.0.0:8002->80/tcp,:::8002->80/tcp

-> 8001번 포트, 8002번 포트가 각각 할당되었음

  • yaml 파일 수정
rapa@rapa:~/0822$ vi docker-compose.yml 
  • 포트를 80번만 남김
    ports:
      - "80"
  • 다시 배포
rapa@rapa:~/0822$ dc up -d 
0822_db_1 is up-to-date
Stopping and removing 0822_web_2 ... done
Recreating 0822_web_1            ... done

-> db는 변경 사항이 없음

  • 생성 확인
rapa@rapa:~/0822$ dc ps
   Name                Command             State                   Ports                 
-----------------------------------------------------------------------------------------
0822_db_1    docker-entrypoint.sh mysqld   Up      3306/tcp, 33060/tcp                   
0822_web_1   httpd -D FOREGROUND           Up      0.0.0.0:49153->80/tcp,:::49153->80/tcp

호스트의 랜덤 포트(49153번) 포트로 할당되었음

  • scale web=3
rapa@rapa:~/0822$ dc scale web=3
WARNING: The scale command is deprecated. Use the up command with the --scale flag instead.
Creating 0822_web_2 ... done
Creating 0822_web_3 ... done
  • 생성 확인
   Name                Command             State                   Ports                 
-----------------------------------------------------------------------------------------
0822_db_1    docker-entrypoint.sh mysqld   Up      3306/tcp, 33060/tcp                   
0822_web_1   httpd -D FOREGROUND           Up      0.0.0.0:49153->80/tcp,:::49153->80/tcp
0822_web_2   httpd -D FOREGROUND           Up      0.0.0.0:49154->80/tcp,:::49154->80/tcp
0822_web_3   httpd -D FOREGROUND           Up      0.0.0.0:49155->80/tcp,:::49155->80/tcp

  • scale web=1
rapa@rapa:~/0822$ dc scale web=1
WARNING: The scale command is deprecated. Use the up command with the --scale flag instead.
Stopping and removing 0822_web_2 ... done
Stopping and removing 0822_web_3 ... done
rapa@rapa:~/0822$ dc ps
   Name                Command             State                   Ports                 
-----------------------------------------------------------------------------------------
0822_db_1    docker-entrypoint.sh mysqld   Up      3306/tcp, 33060/tcp                   
0822_web_1   httpd -D FOREGROUND           Up      0.0.0.0:49153->80/tcp,:::49153->80/tcp
  • test1 디렉토리에 yaml파일 가져오기
rapa@rapa:~/0822$ mkdir test1
rapa@rapa:~/0822$ cd test1

rapa@rapa:~/0822/test1$ cp ../docker-compose.yml .
rapa@rapa:~/0822/test1$ tree
.
└── docker-compose.yml

0 directories, 1 file
  • 배포
rapa@rapa:~/0822/test1$ dc up -d
Creating network "test1_default" with the default driver
Creating test1_db_1 ... done
Creating test1_web_1 ... done
  • 생성 확인
rapa@rapa:~/0822/test1$ dc ps
   Name                 Command             State                   Ports                 
------------------------------------------------------------------------------------------
test1_db_1    docker-entrypoint.sh mysqld   Up      3306/tcp, 33060/tcp                   
test1_web_1   httpd -D FOREGROUND           Up      0.0.0.0:49156->80/tcp,:::49156->80/tcp

-> 현 디렉토리에서 생성된 컨테이너만 보여짐

  • docker network
rapa@rapa:~/0822/test1$ docker network ls 
NETWORK ID     NAME            DRIVER    SCOPE
de17d02308c9   0822_default    bridge    local
9a903e5720fe   bridge          bridge    local
3ead376f089f   host            host      local
39430d1f4412   none            null      local
b49ee53043bc   test1_default   bridge    local

-> 0822_default, test1_default 네트워크가 생성되었다.

rapa@rapa:~/0822/test1$ docker network inspect 0822_default | grep Subnet
                    "Subnet": "172.20.0.0/16",
rapa@rapa:~/0822/test1$ docker network inspect test1_default | grep Subnet
                    "Subnet": "172.21.0.0/16",

-> 서로 다른 대역으로 네트워크가 생성되었다.

  • docer-compose -p 옵션
rapa@rapa:~/0822/test1$ dc -p 0822 ps 
   Name                Command             State                   Ports                 
-----------------------------------------------------------------------------------------
0822_db_1    docker-entrypoint.sh mysqld   Up      3306/tcp, 33060/tcp                   
0822_web_1   httpd -D FOREGROUND           Up      0.0.0.0:49153->80/tcp,:::49153->80/tcp

-> 해당 디렉토리에 있는 컨테이너를 확인

  • down
rapa@rapa:~/0822/test1$ dc -p 0822 down 
Stopping 0822_web_1 ... done
Stopping 0822_db_1  ... done
Removing 0822_web_1 ... done
Removing 0822_db_1  ... done
Removing network 0822_default
rapa@rapa:~/0822/test1$ dc down 
Stopping test1_web_1 ... done
Stopping test1_db_1  ... done
Removing test1_web_1 ... done
Removing test1_db_1  ... done
Removing network test1_default
  • 네트워크 생성 (test1net)
rapa@rapa:~/0822/test1$ docker network create test1net 
588c90a886469b05ad1016576ac637238a12ce541dcb12f9ca9f7ed5343ec45e
  • 컨테이너를 생성한 네트워크에 연결하여 배포 (test1net)
rapa@rapa:~/0822/test1$ docker container run -it \
> --name centos01 \
> --net test1net \
> centos:7
[root@b71c60f5dbf5 /]# 
  • 통신 확인
[root@b71c60f5dbf5 /]# ping www.google.com -c 3
PING www.google.com (142.250.199.100) 56(84) bytes of data.
64 bytes from nrt13s52-in-f4.1e100.net (142.250.199.100): icmp_seq=1 ttl=109 time=32.3 ms
64 bytes from nrt13s52-in-f4.1e100.net (142.250.199.100): icmp_seq=2 ttl=109 time=29.7 ms
64 bytes from nrt13s52-in-f4.1e100.net (142.250.199.100): icmp_seq=3 ttl=109 time=30.6 ms

--- www.google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 29.777/30.957/32.398/1.085 ms
  • 생성 확인 (test1net)
# ctrl + p. q 로 콘솔 빠져나옴 

rapa@rapa:~/0822/test1$ docker container ls --all
CONTAINER ID   IMAGE       COMMAND                  CREATED              STATUS                    PORTS     NAMES
b71c60f5dbf5   centos:7    "/bin/bash"              About a minute ago   Up About a minute                   centos01
rapa@rapa:~/0822/test1$ docker container inspect centos01 | grep NetworkMode
            "NetworkMode": "test1net",
  • yaml 수정 (external: true)
rapa@rapa:~/0822/test1$ vi docker-compose.yml 
version: '3.7'

services:
  web:
    image: httpd
    ports:
      - "80"
    command: httpd -D FOREGROUND
    depends_on:
      - db
    links:
      - db:mysql
    networks:
      - test1net

  db:
    image: mysql:5.7
    environment:
      - MYSQL_ROOT_PASSWORD=test123
      - MYSQL_DATABASE=testdb
    networks:
      - test1net
networks:
  test1net:
    external: true

-> 새로 test1_test1net이 만들어지지 않고, 기존에 생성혰던 네트워크 사용 (test1net)

  • 배포
rapa@rapa:~/0822/test1$ dc up -d
Creating test1_db_1 ... done
Creating test1_web_1 ... done
  • 네트워크 연결 확인 (test1net)
rapa@rapa:~/0822/test1$ docker container inspect test1_web_1 | grep NetworkMode
            "NetworkMode": "test1net",
rapa@rapa:~/0822/test1$ docker container inspect test1_db_1 | grep NetworkMode
            "NetworkMode": "test1net",

-> 새로운 네트워크가 생성되지 않았고 기존에 만들었던 teset1net과 연결되었음

실습 2 - 도커 볼륨 구성

  • 기존 볼륨 활용 가능(네트워크와 동일)
  • 만약 지정하지 않는다면 디렉터리 이름을 이용하여 신규 생성한다.
volumes: 
  - testvolume1:/var/www/html  

-> 0822_testvolume1과 컨테이너의 /var/www/html이 연결

volumes:
  testvolume1: 
    external: true

-> 기존에 만들어 둔 testvolume1을 사용한다.

  • yaml 수정
rapa@rapa:~/0822/test1$ vi docker-compose.yml 
version: '3.7'

services:
  web:
    image: httpd
    ports:
      - "80"
    command: httpd -D FOREGROUND
    depends_on:
      - db
    links:
      - db:mysql
    networks:
      - test1net
    volumes:
      - testvol1:/usr/local/apache2/htdocs

  db:
    image: mysql:5.7
    environment:
      - MYSQL_ROOT_PASSWORD=test123
      - MYSQL_DATABASE=testdb
    networks:
      - test1net
networks:
  test1net:
    external: true

volumes:
  testvol1:
rapa@rapa:~/0822/test1$ dc up -d
Creating volume "test1_testvol1" with default driver
test1_db_1 is up-to-date
Recreating c62f3aebef49_test1_web_1 ... done
rapa@rapa:~/0822/test1$ docker volume ls
local     test1_testvol1
  • yaml 수정
version: '3.7'

services:
  web:
    image: httpd
    ports:
      - "80"
    command: httpd -D FOREGROUND
    depends_on:
      - db
    links:
      - db:mysql
    networks:
      - test1net
    volumes:
      - testvol2:/usr/local/apache2/htdocs

  db:
    image: mysql:5.7
    environment:
      - MYSQL_ROOT_PASSWORD=test123
      - MYSQL_DATABASE=testdb
    networks:
      - test1net
networks:
  test1net:
    external: true

volumes:
  testvol2:
    external: true
  • testvol2 생성
rapa@rapa:~/0822/test1$ docker volume create testvol2
testvol2
  • 다시 배포
rapa@rapa:~/0822/test1$ dc down
Stopping test1_web_1 ... done
Stopping test1_db_1  ... done
Removing test1_web_1 ... done
Removing test1_db_1  ... done
Network test1net is external, skipping
rapa@rapa:~/0822/test1$ dc up -d
Creating volume "test1_testvol2" with default driver
Creating test1_db_1 ... done
Creating test1_web_1 ... done

volume 사용은
1. nfs: 디렉토리 마운트
2. iSCSI: 스토리지에서 volume을 생성하고 이를 컨테이너의 /dev/sda* 과 같은 형태로 연결
3. tmpfs: 디스크가 아니라 RAM에 저장(영구 보관 불가)

  • 호스트의 shared 폴더를 컨테이너에 연결할 것임
rapa@rapa:~/0822/test1$ tree
.
├── docker-compose.yml
└── shared
    └── test.txt
  • yaml 파일 작성
rapa@rapa:~/0822/test1$ vi docker-compose.yml 
  • shared 폴더 마운트 설정
version: '3.7'

services:
  web:
    image: httpd
    ports:
      - "80"
    command: httpd -D FOREGROUND
    depends_on:
      - db
    links:
      - db:mysql
    networks:
      - test1net
    volumes:
      - testvol2:/usr/local/apache2/htdocs
      - /home/rapa/0822/test1/shared:/root

  db:
    image: mysql:5.7
    environment:
      - MYSQL_ROOT_PASSWORD=test123
      - MYSQL_DATABASE=testdb
    networks:
      - test1net
networks:
  test1net:
    external: true

volumes:
  testvol2:
    external: true
  • 배포
rapa@rapa:~/0822/test1$ dc up -d
test1_db_1 is up-to-date
Recreating test1_web_1 ... done
  • 마운트 확인
rapa@rapa:~/0822/test1$ docker container exec test1_web_1 ls /root
test.txt
  • 파일 추가
rapa@rapa:~/0822/test1$ touch shared/ddd.txt
  • 마운트 확인
rapa@rapa:~/0822/test1$ docker container exec test1_web_1 ls /root
ddd.txt
test.txt

실습 3 - extends 옵션 사용하기

  • yaml 파일을 추가적으로 만들거나 하나의 yaml 내에서 추가 컨테이너 내에 기본 내용을 작성하고 이를 다른 파일이나 서비스에서 상속하여 사용하는 방법.
  • 주로 두 개의 파일을 만들어 두고 이를 상속 받는 방법을 사용한다.
  • yaml 작성
rapa@rapa:~/0822/test2$ vi docker-compose.yml 
version: '3.7'

services:
  web:
    extends:
      file: extend-compose.yml
      service: testweb
rapa@rapa:~/0822/test2$ vi extend-compose.yml 
version: '3.7'

services:
  testweb:
    image: httpd
    ports:
      - "80"
  • 배포
rapa@rapa:~/0822/test2$ dc -f docker-compose.yml -f extend-compose.yml up -d 
Creating network "test2_default" with the default driver
Creating test2_web_1     ... done
Creating test2_testweb_1 ... done
  • 생성 확인
rapa@rapa:~/0822/test2$ dc ps
   Name           Command        State                   Ports                 
-------------------------------------------------------------------------------
test2_web_1   httpd-foreground   Up      0.0.0.0:49161->80/tcp,:::49161->80/tcp

-> 웹이 배포되었음

rapa@rapa:~/0822/test2$ docker container ls 
CONTAINER ID   IMAGE       COMMAND                  CREATED              STATUS              PORTS                                     NAMES
537a781b3780   httpd       "httpd-foreground"       About a minute ago   Up About a minute   0.0.0.0:49162->80/tcp, :::49162->80/tcp   test2_testweb_1
a24dfcf0a809   httpd       "httpd-foreground"       About a minute ago   Up About a minute   0.0.0.0:49161->80/tcp, :::49161->80/tcp   test2_web_1


rapa@rapa:~/0822/test2$ dc down 
Stopping test2_web_1 ... done
WARNING: Found orphan containers (test2_testweb_1) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.
Removing test2_web_1 ... done
Removing network test2_default
ERROR: error while removing network: network test2_default id 5bd52c78f463e1968fd2e0528bacb0e96b5aa73dcae2e19ce51dd4a6c06d1acc has active endpoints

실습 4 - wordpress 배포

미리 생성해 둔 네트워크(test1net), 볼륨(testvol3)을 활용하여 외부에 워드프레스 서비스를 제공한다. 단, db의 /var/lib/mysql 은 testvol2에 마운트 된다. 또한 워드프레스는 외부 노출 시 8001-8009를 활용한다.

  • 볼륨 생성 (testvol3)
rapa@rapa:~/0822/wordpress$ docker volume create testvol3 
testvol3
  • yaml 수정
rapa@rapa:~/0822/wordpress$ vi docker-compose.yml 
version: '3.7'
services:
  wordpress:
    image: wordpress
    networks:
      - test1net
    links:
      - "db:mysql"
    ports:
      - "8001-8009:80"
    depends_on:
      - db
    environment:
      - WORDPRESS_DB_PASSWORD=test123
      - WORDPRESS_DB_USER=root
      - WORDPRESS_DB_NAME=testdb
    volumes:
      - ./www:/var/www/html
  db:
    image: mysql:5.7
    networks:
      - test1net
    volumes:
      - testvol3:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=test123
      - MYSQL_DATABASE=testdb
networks:
  test1net:
    external: true

volumes:
  testvol3:
    external: true
  • 배포
rapa@rapa:~/0822/wordpress$ dc up -d --scale wordpress=2
Creating wordpress_db_1 ... done
WARNING: The "wordpress" service specifies a port on the host. If multiple containers for this service are created on a single host, the port will clash.
Creating wordpress_wordpress_1 ... done
Creating wordpress_wordpress_2 ... done
  • 확인
rapa@rapa:~/0822/wordpress$ dc ps 
        Name                       Command               State                  Ports                
-----------------------------------------------------------------------------------------------------
wordpress_db_1          docker-entrypoint.sh mysqld      Up      3306/tcp, 33060/tcp                 
wordpress_wordpress_1   docker-entrypoint.sh apach ...   Up      0.0.0.0:8005->80/tcp,:::8005->80/tcp
wordpress_wordpress_2   docker-entrypoint.sh apach ...   Up      0.0.0.0:8004->80/tcp,:::8004->80/tcp

-> 8004, 8005

  • 8004 포트 접속

  • 8005 포트 접속

-> 8004로 리다이렉트 됨

  • down
rapa@rapa:~/0822/wordpress/www$ dc down 
Stopping wordpress_wordpress_2 ... done
Stopping wordpress_wordpress_1 ... done
Stopping wordpress_db_1        ... done
Removing wordpress_wordpress_2 ... done
Removing wordpress_wordpress_1 ... done
Removing wordpress_db_1        ... done
Network test1net is external, skipping

실습 5 - nginx, cAdvisor 배포

  1. mkdir 0822/testlab 을 만든다.
  2. 해당 디렉토리 내에서 Dockerfile을 생성하여 이미지 testweb:1.0을 생성한다.
    이미지는 아래의 내용을 포함해야 한다.
    베이스 이미지: ubuntu:18.04
    설치 패키지: nginx
    0822/testlab에 index.html 파일을 curl을 이용하여 간단히 생성하고, 해당 파일을 nginx의 기본 웹 홈디렉토리에 올린다.
    80번 포트가 열려있어야 하며, 컨테이너로 배포 시에는 자동으로 nginx가 실행되어야 한다.
  3. docker-compose 파일을 작성한다. 아래의 내용을 포함한다.
web:
  image: testweb:1.0
  environment: 
    - DB_NAME=testdb 
    - DB_USER=root
    - DB_PASSWORD=test123
db: 
  image: mysql:5.7 
  environment: 
    - MYSQL_ROOT_PASSWORD=test123 
    - MYSQL_DATABASE=testdb 

나중에 docker container exec testlab1_web_1 env 입력하면 위의 정보가 보여야 함
web은 외부 노출 시 자신의 80번 포트를 호스트의 8881-8889를 사용한다.
web과 db 모두 testnetwork1에 연결되어야 한다. 또한 생성된 컨테이너는 linux 재부팅 시 자동으로 활성화되어야 한다.
db는 미리 생성해 두었던 testvolume1에 연결되어야 하는데, /var/lib/mysql로 마운트된다.

  1. docker container run을 활용하여 cAdvisor를 설치하고, 이를 통해 앞서 만들어 두었던 컨테이너들을 확인할 수 있어야 한다. 물론 cAdvisor도 testnetwork1에 연결되어있어야 한다.

step 1) 볼륨 생성 (testvolume1)

rapa@rapa:~/0822/testlab$ docker volume create testvolume1
testvolume1

step 2) 네트워크 생성 (testnetwork1)

rapa@rapa:~/0822/testlab$ docker network create testnetwork1
78e5b3d9d96ca0b621dad37123955f5d628ef1942c90eed5f9139936973b478a

step 3) index.html 생성

rapa@rapa:~/0822/testlab$ curl https://www.naver.com > index.html
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  247k    0  247k    0     0  1794k      0 --:--:-- --:--:-- --:--:-- 1781k

step 4) Dockerfile 생성 (ubuntu, nginx)

rapa@rapa:~/0822/testlab$ vi Dockerfile 
FROM ubuntu:18.04
RUN apt-get update 
RUN apt-get -y install nginx

ADD index.html /var/www/html/index.html

EXPOSE 80

CMD nginx -g 'daemon off;'

step 5) 이미지 빌드 (testweb:1.0)

rapa@rapa:~/0822/testlab$ docker build -t testweb:1.0 .
Successfully built 00db770b08de
Successfully tagged testweb:1.0

step 6) docker compose yaml 파일 작성 (web, db)

rapa@rapa:~/0822/testlab$ vi docker-compose.yml
version: '3.7'

services:
  web:
    image: testweb:1.0
    environment:
      - DB_NAME=testdb
      - DB_USER=root
      - DB_PASSWORD=test123
    networks:
      - testnetwork1
    ports:
      - "8881:8889:80"
    depends_on:
      - db
    links:
      - db:mysql
    restart: always

  db:
    image: mysql:5.7
    environment:
      - MYSQL_ROOT_PASSWORD=test123
      - MYSQL_DATABASE=testdb
    networks:
      - testnetwork1
    volumes:
      - testvolume1:/var/lib/mysql
    restart: always       
 
networks:  
  testnetwork1:
    external: true
    
volumes:
  testvolume1:
    external: true

step 7) docker compose 배포

rapa@rapa:~/0822/testlab$ dc up -d
Creating testlab_db_1 ... done
Creating testlab_web_1 ... done

step 8) cAdvisor 배포

rapa@rapa:~/0822/testlab$ docker container run -d \
> -v /:/rootfs:ro \
> -v /var/run:/var/run:rw \
> -v /sys:/sys:ro \
> -v /var/lib/docker/:/var/lib/docker:ro \
> -p 9559:8080 \
> --name cadvisor \
> --net testnetwork1 \
> google/cadvisor
Unable to find image 'google/cadvisor:latest' locally
latest: Pulling from google/cadvisor
ff3a5c916c92: Pull complete 
44a45bb65cdf: Pull complete 
0bbe1a2fe2a6: Pull complete 
Digest: sha256:815386ebbe9a3490f38785ab11bda34ec8dacf4634af77b8912832d4f85dca04
Status: Downloaded newer image for google/cadvisor:latest
78241980658fefa999e80a21c723b920cdaa2ee27ed88f4201a6725779fe2a2b

step 9) 확인

rapa@rapa:~/0822/testlab$ dc ps
    Name                   Command               State                  Ports                
---------------------------------------------------------------------------------------------
testlab_db_1    docker-entrypoint.sh mysqld      Up      3306/tcp, 33060/tcp                 
testlab_web_1   /bin/sh -c nginx -g 'daemo ...   Up      0.0.0.0:8889->80/tcp,:::8889->80/tcp

-> 웹서버 포트: 8889

localhost:8889 접속

localhost:9559 접속 (cAdvisor)

-> testlab_web_1, testlab_db_1이 보인다.

Docker Swarm

EKS/ECS/GKE

  • 만약 위와 같이 노드를 3개 배포한다면, KVM은 가상 서버를 manager(마스터) 노드를 포함하여 총 4개 생성한다.
  • 노드들에는 도커 엔진과 쿠버네티스가 설치되며, 클러스터와 overlay 네트워크가 구성된다.
  • 세 노드는 자동으로 마스터 노드에 join 된다. 마스터 노드는 미리 토큰을 두 개 발행한다.
  • manager용 토큰, worker용 토큰이 발행된다.
  • worker용 토큰은 worker가 조인할 때 사용된다.
  • 도커 네트워크 드라이버에는 bridge, host, none이 있는데 overlay 네트워크 드라이버도 생성된다.
  • manager 노드는 manager의 역할과 worker의 역할을 둘 다 수행한다. 쿠버네티스를 사용한다면 manager 노드에 runtime 역할하지 않는다.

출처: https://appfleet.com/blog/top-10-container-orchestration-tools/

구성 사항:

						    CPU  RAM   NIC(VMnet10) 
manager(private-registry)    2    4    211.183.3.100 
worker1	                     2    2    211.183.3.101
worker2                      2    2    211.183.3.102
worker3                      2    2    211.183.3.103 
profile
take a look

0개의 댓글