버전 비교

  • 이 줄이 추가되었습니다.
  • 이 줄이 삭제되었습니다.
  • 서식이 변경되었습니다.

...

정보
  • Control groups : 리소스 사용량(CPU/Memory/Network/Storage) 결정

  • Namespaces : 자원을 격리(네트워크/프로세스/사용자정보 - 공개 범위를 결정)

  • Union mount file system : 컨테이너 이미지를 효율적으로 관리

...

1.4.1

...

컨테이너

  • 컨테이너는 애플리케이션을 실행하는 데 사용될 수 있는 OS 가상화의 한 형태입니다

  • 이를 위해 컨테이너는 리눅스 커널의 몇 가지 새로운 기능으로 제작되었으며, 그 중 두 가지 주요 기능은 "namespace"와 "cgroups"입니다.

...

1.4.2

...

리눅스 네임스페이스

  • 네임스페이스는 리눅스 커널의 기능 중 하나이며 리눅스의 컨테이너의 기본적인 측면입니다.반면에 네임스페이스는 격리 계층을 제공합니다.네임스페이스는 한 프로세스 집합은 한 리소스 집합을 보고 다른 프로세스 집합은 다른 리소스 집합을 보도록 커널 리소스를 분할하는 리눅스 커널의 기능입니다.

...

코드 블럭
root@ubuntu-focal:~# exit
exit
root@ubuntu-focal:~# ps aux
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.0  0.8 102540  8840 ?        Ss   12:04   0:02 /sbin/init
root           2  0.0  0.0      0     0 ?        S    12:04   0:00 [kthreadd]
root           3  0.0  0.0      0     0 ?        I<   12:04   0:00 [rcu_gp]
root           4  0.0  0.0      0     0 ?        I<   12:04   0:00 [rcu_par_gp]
root           6  0.0  0.0      0     0 ?        I<   12:04   0:00 [kworker/0:0H-kblockd]

...

1.4.3

...

Cgroup

리눅스 네임스페이스로 다른 프로세스와는 별도의 프로세스를 만들 수도 있었습니다.

...

정보

cgroups로 제어할 수 있는 일반적인 리소스는 다음과 같습니다.

  • CPU: 프로세스 그룹에서 사용하는 CPU 시간을 제한

  • 메모리: 프로세스 그룹에서 사용하는 메모리 양을 제한합니다제한합니다.

  • I/O: 프로세스 그룹에서 사용하는 Disk I/O 양 제한

  • 네트워크: 프로세스 그룹에서 사용하는 네트워크 대역폭의 양을 제한합니다제한합니다.

1.5 컨테이너의 장점

(1) 가벼움

  • 사용자의 Request Traffic 이 증가함에 따라, 가상머신이나 컨테이너를 추가적으로 배포합니다.

  • 가상머신의 크기는 최소 몇 GB이지만, 컨테이너의 경우 Guest OS가 없기에 MB단위의 크기를 가집니다.

  • 가상머신은 배포하는데 수분에서 수 십분의 시간이 소요되지만, 컨테이너는 배포에 소요되는 몇 초 밖에 걸리지 않습니다.

...

코드 블럭
vagrant@ubuntu-focal:~$ sudo apt update 
vagrant@ubuntu-focal:~$ docker images
vagrant@ubuntu-focal:~$ sudo -i
root@ubuntu-focal:~# apt install docker.io

...

코드 블럭
저장소 이름 (Repository Name) : default == docker hub 
이미지 이름 (Image Name) : nginx
이미지 태그 (Image Tag) : lastest (default)

(4) 이미지 가지고 오기

코드 블럭
$ docker pull nginx:latest
$ docker images
코드 블럭
# tag를 지정해주지 않으면 default로 latest 버전을 가져옵니다.
# tag를 지정할 경우 
# docker pull nginx:latest 
# 위의 명령어 대로 pull 가능
root@ubuntu-focal:~# docker pull nginx:latest
latest: Pulling from library/nginx
52d2b7f179e3: Pull complete
fd9f026c6310: Pull complete
055fa98b4363: Pull complete
96576293dd29: Pull complete
a7c4092be904: Pull complete
e3b6889c8954: Pull complete
da761d9a302b: Pull complete
Digest: sha256:104c7c5c54f2685f0f46f3be607ce60da7085da3eaa5ad22d3d9f01594295e9c
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
# 이미지 확인
root@ubuntu-focal:~# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
nginx        latest    eea7b3dcba7e   2 weeks ago   187MB

...

코드 블럭
# docker run 이라는 명령어로 컨테이너를 실행시켜줍니다.
# docker run <옵션> <이미지 이름> <실행할 파일>
root@ubuntu-focal:~# docker run -it -d -p 80:80 --name=nginx nginx:latest
1303feec17205609e6303e72831084babeaebdfaec3bf9bf0f6f4e4b39082dd1
# 옵션 -i(interactive), -t(Pseudo-tty) -> Bash Shell에 입력 및 출력을 할 수 있습니다.
# 옵션 --name -> 컨테이너의 이름을 지정해 줍니다.
# 옵션 -d -> daemonized
# 옵션 -p -> 포트포워딩
  ex) 80:80 = [호스트의 포트] : [컨테이너의 포트]
root@ubuntu-focal:~# docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS                                   NAMES
1303feec1720   nginx:latest   "/docker-entrypoint.…"   14 seconds ago   Up 14 seconds   0.0.0.0:8080->80/tcp, :::8080->80/tcp   nginx
root@ubuntu-focal:~# curl http://localhost:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
정보

Docker docker create : 도커 이미지에서 새로운 컨테이너를 생성합니다. 그러나 즉시 실행되지는 않습니다

Docker docker start : 중지된 컨테이너를 시작합니다. docker create 명령을 사용하여 컨테이너를 만든 경우 이 명령으로 시작할 수 있습니다.

Docker docker run : create와 start의 조합으로 새 컨테이너를 생성하고 시작합니다. docker run 명령은 로컬 시스템에서 이미지를 찾지 못하는 경우 Docker Hub에서 이미지를 가져와서 컨테이너를 생성하고 실행합니다.

...

코드 블럭
root@ubuntu-focal:~# apt install nginx

#설치 확인
root@ubuntu-focal:~# nginx -v
nginx version: nginx/1.18.0 (Ubuntu)
정보

socket() [::]:80 failed 에러가 나면, /etc/nginx/sites-enabled/default 에서

listen [::]:80 default_server; 삭제

(3) Nginx 확인

  • nginx를 패키지를 통하여 설치 하였기에 Default directory가 /etc/nginx 아래에 위치하게 됩니다.

  • 직접 compile한 경우에 경로는 /usr/local/nginx/conf 혹은 /use/local/etc/nginx 에 위치합니다.

...

(1) Dockerfile 생성

코드 블럭
cd /home/vagrant
vi Dockerfile

3/Dockerfile

코드 블럭
FROM ubuntu:20.04
MAINTAINER Hojin kim "khoj@osci.kr" 
RUN apt update
RUN apt install -y nginx
WORKDIR /etc/nginx 
CMD ["nginx", "-g", "daemon off;"]
EXPOSE 80 

...

코드 블럭
root@ubuntu-focal:~# docker images
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
mynginx      0.1       03de8991a4f8   11 minutes ago   178MB
ubuntu       20.04     6df894023726   5 weeks ago      72.8MB
root@ubuntu-focal:~# docker tag mynginx:0.1 mynginx:0.2
root@ubuntu-focal:~# docker images
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
mynginx      0.1       03de8991a4f8   12 minutes ago   178MB
mynginx      0.2       03de8991a4f8   12 minutes ago   178MB
ubuntu       20.04     6df894023726   5 weeks ago      72.8MB

 

성능이슈가 발생할수 있으므로, vagrant를 halt 시켜놓는다.

코드 블럭
root@k8s:/home/vagrant# exit
logout
vagrant@k8s:~$ exit
logout

$ vagrant halt -f default
==> default: Forcing shutdown of VM...

...

3. 컨테이너 Orchestration

Container Orchestration은 애플리케이션을 구성하고 있는 수십 또는 수백 개의 컨테이너와 호스트들을 배포하고 관리하기 위한 도구입니다.

...