Dev건 Ops건 쿠버네티스를 배우기에 앞아서 컨테이너에 대한 기본적인 이해를 갖고 있는 것이 좋다. Dev는 이미지를 빌드하는 업무도 책임져야하기 때문에, 더 깊이 있게 이해해야할 한다.

도커로 대표되는 컨테이너 환경의 연습은 손쉽게 구축할 수 있다. 도커의 경우 아래 문서에 플랫폼 별로 설명되어 있다.

https://docs.docker.com/engine/install/

왜 하필 호스트(VM) 1개 짜리인가?

1이 시작이기 때문이다. 쿠버네티스를 흔히 “컨테이너 오케스트레이션” 도구라고 말을 한다. 이것은 1대의 호스트가 아니라 최소 2대 이상의 경우를 전제로 한다. 실제 서비스용으로 구성하면 3+3해서 6대는 해야한다. 점점 뭔가 복잡하고 어려워지는 것 같다…

그래서 시작은 간단하게 하는 것이 좋다. 그냥 1대.

얼마나 좋은가. 내 PC에서도 충분히 돌릴 수 있고, 클라우드에 무료 크레딧 받아서 몇달에서 1년까지 돌릴 수도 있다.

그 중에서 이 글은 내 PC에 무료 솔루션인 VMware Workstation 16 Player를 설치하고, 무료인 Ubuntu 20.04를 다운로드 받아서, 평생 무료인 컨테이너 실습환경을 만들어 보고자 한다.

일단 이거가지고 Docker Compose까지 좀 써보고, 쿠버네티스로 넘어가려고 한다.

VMware Workstation 16 Player 다운로드 및 설치

다른 글에서 설명해 놓았다. 아직 설치 안한분들은 다음 링크에 있는 글들 보고 설치하기 바란다.
( Fusion도 써보고는 싶지만, 아쉽게도 mac이 없다. 그래도 90년대에는 mac 잡지에 원고도 쓰고 그랬는디 ㅠ.ㅠ )

https://www.098.co.kr/tag/player/

Ubuntu 20.04 다운로드

홈페이지에서 다음과 같은 절차로 받으면 된다.

귀찮으면 https://releases.ubuntu.com/20.04.1/ubuntu-20.04.1-live-server-amd64.iso 바로 클릭 ^^

Player에서 Ubuntu 가상머신(VM) 만들고 설치하기

쓰다보니 너무 길어서 다른 글로 따로 만들었다. 아래 링크에서 보고 진행하기 바란다.

Docker 설치

우분투 리눅스에 도커를 설치하기 위한 절차는 아래 URL에서 얻을 수 있다.

https://docs.docker.com/engine/install/ubuntu/

이 내용을 보고 한번 따라해 보도록 하겠다.

OS 요구사항

Docker Engine은 다음 3가지 버전의 우분투 리눅스를 지원한다. 64비트 버전만 지원한다.

  • Ubuntu Focal 20.04 (LTS)
  • Ubuntu Bionic 18.04 (LTS)
  • Ubuntu Xenial 16.04 (LTS)

이전 버전 제거

우분투 설치할 때에 Docker 관련 패키지를 설치하지 않는 형태로 가상머신을 만들었다. 그러나 혹시 모르니 관련된 패키지 제거 명령을 한번 실행해준다. 이 예에서는 설치된 것이 없기 때문에 특별히 제거하는 내용이 표시되지는 않았다.

ikhwan@docker-lab:~$ sudo apt-get remove docker docker-engine docker.io containerd runc
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package docker-engine
ikhwan@docker-lab:~$

레포지토리를 사용한 설치

설치는 크게 패키지 파일을 받아서 하는 방법과 레포지토리(repository)를 추가하고 레포지토리를 통해 패키지를 다운로드 받는 방법이 있다. 조금 번거럽기는 하지만 레포티토리를 사용한 설치 방법으로 진행해 보겠다.

sudo apt-get update
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
  • 위 두 명령을 각각 복사해서 실행한다. 중간에 “Do you want to continue? [Y/n]”와 같이 묻는 내용이 나오면 Y를 입력한다.
ikhwan@docker-lab:~$ sudo apt-get update
Hit:1 http://kr.archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://kr.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:3 http://kr.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:4 http://kr.archive.ubuntu.com/ubuntu focal-security InRelease
Reading package lists... Done
ikhwan@docker-lab:~$ sudo apt-get install \
>     apt-transport-https \
>     ca-certificates \
>     curl \
>     gnupg-agent \
>     software-properties-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
ca-certificates is already the newest version (20190110ubuntu1.1).
ca-certificates set to manually installed.
curl is already the newest version (7.68.0-1ubuntu2.2).
curl set to manually installed.
software-properties-common is already the newest version (0.98.9.2).
software-properties-common set to manually installed.
The following NEW packages will be installed:
  apt-transport-https gnupg-agent
0 upgraded, 2 newly installed, 0 to remove and 3 not upgraded.
Need to get 6,944 B of archives.
After this operation, 206 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://kr.archive.ubuntu.com/ubuntu focal-updates/universe amd64 apt-transport-https all 2.0.2ubuntu0.1 [1,708 B]
Get:2 http://kr.archive.ubuntu.com/ubuntu focal/universe amd64 gnupg-agent all 2.2.19-3ubuntu2 [5,236 B]
Fetched 6,944 B in 1s (6,029 B/s)
Selecting previously unselected package apt-transport-https.
(Reading database ... 70877 files and directories currently installed.)
Preparing to unpack .../apt-transport-https_2.0.2ubuntu0.1_all.deb ...
Unpacking apt-transport-https (2.0.2ubuntu0.1) ...
Selecting previously unselected package gnupg-agent.
Preparing to unpack .../gnupg-agent_2.2.19-3ubuntu2_all.deb ...
Unpacking gnupg-agent (2.2.19-3ubuntu2) ...
Setting up apt-transport-https (2.0.2ubuntu0.1) ...
Setting up gnupg-agent (2.2.19-3ubuntu2) ...
ikhwan@docker-lab:~$
  • 다음 명령을 실행해서 도커의 GPG 키를 추가한다.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
ikhwan@docker-lab:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
OK
ikhwan@docker-lab:~$
  • 다음 명령으로 핑거프린트(fingerprint) 값 “9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88″을 확인한다.
sudo apt-key fingerprint 0EBFCD88
ikhwan@docker-lab:~$ sudo apt-key fingerprint 0EBFCD88
pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [ unknown] Docker Release (CE deb) <docker@docker.com>
sub   rsa4096 2017-02-22 [S]

ikhwan@docker-lab:~$
  • 다음 명령으로 레포지토리를 추가한다.
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
ikhwan@docker-lab:~$ sudo add-apt-repository \
>    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
>    $(lsb_release -cs) \
>    stable"
Get:1 https://download.docker.com/linux/ubuntu focal InRelease [36.2 kB]
Get:2 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages [3,684 B]
Hit:3 http://kr.archive.ubuntu.com/ubuntu focal InRelease
Hit:4 http://kr.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:5 http://kr.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:6 http://kr.archive.ubuntu.com/ubuntu focal-security InRelease
Fetched 39.8 kB in 2s (23.0 kB/s)
Reading package lists... Done
ikhwan@docker-lab:~$
  • 다음 명령으로 도커 관련 패키지를 설치한다. 중간에 “Do you want to continue? [Y/n]”와 같이 묻는 내용이 나오면 Y를 입력한다.
sudo apt-get update && sudo apt-get install docker-ce docker-ce-cli containerd.io
ikhwan@docker-lab:~$ sudo apt-get update && sudo apt-get install docker-ce docker-ce-cli containerd.io
Hit:1 https://download.docker.com/linux/ubuntu focal InRelease
Hit:2 http://kr.archive.ubuntu.com/ubuntu focal InRelease
Hit:3 http://kr.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:4 http://kr.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:5 http://kr.archive.ubuntu.com/ubuntu focal-security InRelease
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  aufs-tools cgroupfs-mount pigz
The following NEW packages will be installed:
  aufs-tools cgroupfs-mount containerd.io docker-ce docker-ce-cli pigz
0 upgraded, 6 newly installed, 0 to remove and 3 not upgraded.
Need to get 91.2 MB of archives.
After this operation, 410 MB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 https://download.docker.com/linux/ubuntu focal/stable amd64 containerd.io amd64 1.3.7-1 [24.3 MB]
Get:2 http://kr.archive.ubuntu.com/ubuntu focal/universe amd64 pigz amd64 2.4-1 [57.4 kB]
Get:3 http://kr.archive.ubuntu.com/ubuntu focal/universe amd64 aufs-tools amd64 1:4.14+20190211-1ubuntu1 [104 kB]
Get:4 http://kr.archive.ubuntu.com/ubuntu focal/universe amd64 cgroupfs-mount all 1.4 [6,320 B]
Get:5 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce-cli amd64 5:19.03.13~3-0~ubuntu-focal [44.2 MB]
Get:6 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce amd64 5:19.03.13~3-0~ubuntu-focal [22.6 MB]
Fetched 91.2 MB in 8s (11.2 MB/s)
Selecting previously unselected package pigz.
(Reading database ... 70885 files and directories currently installed.)
Preparing to unpack .../0-pigz_2.4-1_amd64.deb ...
Unpacking pigz (2.4-1) ...
Selecting previously unselected package aufs-tools.
Preparing to unpack .../1-aufs-tools_1%3a4.14+20190211-1ubuntu1_amd64.deb ...
Unpacking aufs-tools (1:4.14+20190211-1ubuntu1) ...
Selecting previously unselected package cgroupfs-mount.
Preparing to unpack .../2-cgroupfs-mount_1.4_all.deb ...
Unpacking cgroupfs-mount (1.4) ...
Selecting previously unselected package containerd.io.
Preparing to unpack .../3-containerd.io_1.3.7-1_amd64.deb ...
Unpacking containerd.io (1.3.7-1) ...
Selecting previously unselected package docker-ce-cli.
Preparing to unpack .../4-docker-ce-cli_5%3a19.03.13~3-0~ubuntu-focal_amd64.deb ...
Unpacking docker-ce-cli (5:19.03.13~3-0~ubuntu-focal) ...
Selecting previously unselected package docker-ce.
Preparing to unpack .../5-docker-ce_5%3a19.03.13~3-0~ubuntu-focal_amd64.deb ...
Unpacking docker-ce (5:19.03.13~3-0~ubuntu-focal) ...
Setting up aufs-tools (1:4.14+20190211-1ubuntu1) ...
Setting up containerd.io (1.3.7-1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service.
Setting up docker-ce-cli (5:19.03.13~3-0~ubuntu-focal) ...
Setting up pigz (2.4-1) ...
Setting up cgroupfs-mount (1.4) ...
Setting up docker-ce (5:19.03.13~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 systemd (245.4-4ubuntu3.2) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.1) ...
ikhwan@docker-lab:~$

Docker 동작 확인

  • 아래 명령어를 입력해서 도커가 잘 동작하는지 확인한다.
sudo docker run hello-world
  • 아래와 같이 중간에 “Hello from Docker!”라고 표시되면 잘 동작하는 것이다.
ikhwan@docker-lab:~$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:4cf9c47f86df71d48364001ede3a4fcd85ae80ce02ebad74156906caff5378bc
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

ikhwan@docker-lab:~$

이제 고래와 함께 컨테이너를 만들고 놀 수 있는 준비가 끝났다.

앞으로는

  • 도커의 기본적인 명령어를 배우고
  • 글쓴이 블로그에서 사용되고 있는 워드프레스 환경을 도커를 이용해서 구현해보고
  • Docker Compose를 활용해서 워드프레스와 같이 여러 컨테이너가 함께 동작하는 환경을 간편히 설정해보고

도커에 대한 입문 과정을 마무리 하고자 한다.

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

You May Also Like

[Docker] What is a Container?

컨테이너란? 소프트웨어의 표준화된 단위 소프트웨어를 개발, 발송, 배포를 위한 표준화된 단위로 패키지화 컨테이너는 코드와 그 모든 의존성을 패키징하여…

containerd 소개

단순성(simplicity), 견고성(robustness), 이식성(portability)에 중점을 둔 업계 표준 컨테이너 런타임 containerd가 CNCF에서 졸업! 2019년 2월 28일 현재, containerd는 Kubernetes,…

[Docker] Docker overview

Docker는 애플리케이션 개발, 발송, 실행을 위한 개방형 플랫폼이다. Docker를 사용하면 소프트웨어를 신속하게 제공할 수 있도록 애플리케이션과 인프라를 분리할…