Docker?

LXC(Linux Containers) 개념에서 시작하며 기존 가상머신의 단점의 극복과 장점을 극대화 시킨 가상화 어플리케이션 이며,
Hypervisor과 같이 운영체제를 통으로 가상화 하기 보단 Host OS와 Container OS의 다른 부분만을 패키징하여 격리시켜 주는 도구 입니다.
 Hypervisors_LXC그림1. Hypervisor & Linux Container 차이점

Docker 0.8x 버전 이하에서 LXC 드라이버에 의존해서 동작하였는데 0.9x 버전부터는 libcontainer 드라이버가 내장으로 들어가 있어서,

LXC 드라이버 없이 커널 컨테이너 API를 액세스할 수 있게 되었습니다.

(namespaces, control groups, capabilities, apparmor profiles, network interfaces, firewalling rules)

docker-execdriver-diagram그림2. New default driver: libcontainer

 

그리고, Docker는 Hypervisor 위에 올려져 있는 환경에서도 동작합니다. (AWS, KVM, XEN, VMware, Virtualbox…)

Docker 설치

Ubuntu 12.04 LTS (64bit), Docker 0.9.1 버전에서 테스트 되었으며 Docker 공식 문서를 참고하여 정리한 내용입니다.
최신 업데이트를 진행하고 리부팅 합니다.
root@ruo91:~# apt-get update
root@ruo91:~# apt-get install linux-image-generic-lts-raring linux-headers-generic-lts-raring
root@ruo91:~# reboot
Docker 저장소 key를 등록 합니다.
root@ruo91:~# apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9

 

Docker 저장소 등록 및 lxc-docker 패키지를 설치 합니다.

root@ruo91:~# echo "deb http://get.docker.io/ubuntu docker main" > /etc/apt/sources.list.d/docker.list
root@ruo91:~# apt-get update
root@ruo91:~# apt-get install lxc-docker

Docker 설치는 끝났습니다.

 

Container OS 설치
HostOS는 Ubuntu입니다. 여기서 설치할 Container OS는 CentOS로 하겠습니다.
설치 이미지는 https://index.docker.io/ 웹에서 Official image와 custom image를 찾아볼수 있으며, 명령어로도 찾아 볼수 있습니다.
root@ruo91:~# docker search centos
NAME                                     DESCRIPTION                                     STARS     OFFICIAL   TRUSTED
centos                                                                                   38
tianon/centos                            CentOS 5 and 6, created using rinse instea...   14
tutum/centos                             DEPRECATED. Use tutum/centos-6.4 instead. ...   5
kalefranz/centos                                                                         2                    [OK]
hagix9/centos65                          CentOS6.5 that init.d init and ssh and com...   1
flores314/centos65                       Docker image base. Built from a CentOS 6.5...   1
longsight/centos-dspace                                                                  1                    [OK]
quagbrain/centos5.9                                                                      1
hnakamur/centos                          CentOS 6.5 x86_64 base image                    1
markshao/centos                                                                          1
goyalankit/centos-updated                                                                1
hansode/centos-6.5-x86_64                * centos-6.5 minimal * openssh openssh-cli...   1
hansode/centos-6-x86_64                  * centos-6.5 minimal * openssh openssh-cli...   1
tutum/centos-6.4                         Centos 6.4 image with SSH access. For the ...   1                    [OK]
hzhang/centos-nginx                                                                      1                    [OK]
mbkan/lamp                               centos with ssh, LAMP, PHPMyAdmin(root pas...   1
fbreton/centos-ssh                                                                       1
zwxajh/centos                            centos 6 base system.                           1
dockerfiles/centos-lamp                                                                  1                    [OK]
swflint/sbcl-slime                       This is a container based on swflint/sbcl-...   1
saltstack/centos-6-minimal                                                               1                    [OK]
..............
......................

 

Docker repository에서 CentOS 이미지를 다운로드 합니다.

root@ruo91:~# docker pull centos
Pulling repository centos
539c0211cd76: Downloading [===>                                               ] 6.869 MB/98.56 MB 47s

완료 될때까지 기다립니다.

Pulling repository centos
539c0211cd76: Download complete

 

다운로드한 이미지를 아래 명령어로 확인이 가능합니다.

root@ruo91:~# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              6.4                 539c0211cd76        11 months ago       300.6 MB

 

배포

배포는 Container OS 실행 -> 필요 패키지 설치 및 설정 -> 변경 사항 적용 -> 저장소 업로드 순입니다. 

Docker의 공식 저장소에 가입을 합니다.
가입후 HostOS에서 로그인을 합니다.
root@ruo91:~# docker login
Username: ruo91
Password:
Email: ruo91@yongbok.net
Login Succeeded

로그인이 완료 되면 해당 디렉토리에 .dockercfg 라는 설정파일이 생성 됩니다.

 

1. Container OS 실행
root@ruo91:~# docker run -i -t centos /bin/bashbash-4.1#

 

2. 필요 패키지 및 설정

bash-4.1# rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
bash-4.1# yum install -y nginx
bash-4.1# exit

 

3. 변경 사항 적용

commit 사용법은 아래와 같습니다.

docker commit [options] [container_id] [Repos username/Image-Name]

container id는 docker ps 명령어를 통해 알수 있습니다.

root@ruo91:~# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
b4f8edaf1627        centos:6.4          /bin/bash           11 minutes ago      Exit 0                                  desperate_lumiere

 

변경 사항을 적용합니다.

root@ruo91:~# docker commit \
--author="Yong-Bok Kim <ruo91@yongbok.net>" \
--message="CentOS 6.5 x86_64 - Nginx" b4f8edaf1627 ruo91/centos-nginx
37492ee2ba967147a22500432cd8af52330c54438076217186e2552fa7cd5c84

 

4. 저장소 업로드

변경 사항이 적용 되었으므로 docker image 저장소에 해당 이미지를 업로드 합니다.
root@ruo91:~# docker push ruo91/centos-nginx
The push refers to a repository [ruo91/centos-nginx] (len: 1)
Sending image list
Pushing repository ruo91/centos-nginx (1 tags)
539c0211cd76: Image already pushed, skipping
37492ee2ba96: Pushing [===>                                               ] 23.86 MB/379.5 MB 4m25s

업로드 완료

root@ruo91:~# docker push ruo91/centos-nginx
The push refers to a repository [ruo91/centos-nginx] (len: 1)
Sending image list
Pushing repository ruo91/centos-nginx (1 tags)
539c0211cd76: Image already pushed, skipping
37492ee2ba96: Image successfully pushed
Pushing tag for rev [37492ee2ba96] on {https://registry-1.docker.io/v1/repositories/ruo91/centos-nginx/tags/latest}

업로드 된 이미지는 https://index.docker.io/ 와 docker search 에서 확인이 가능 하게 됩니다.

 배포한 이미지를 설치 하려면 아래와 같이 다운로드 하시면 됩니다.
root@ruo91:~# docker pull ruo91/centos-nginx

감사합니다. 😀