다른 포스팅에서 윈도우에 도커를 설치하는 방법을 설명하였다.
윈도우에 도커를 설치하면 발생하는 문제점
윈도우에 도커를 설치하면 Docker Desktop이 설치되는데, 이것이 WSL2(Windows Subsystme for Linux2)라는 것을 사용한다. 이것도 일종의 하이퍼바이자러서 VMWare Workstation이나 Oracle VirtualBox와 사용에 있어서 몇가지 충돌이 발생한다. 따라서 VMware Workstation이나 Oracle VirtualBox를 전문적으로 사용하는 사용자는 여러가지 불편을 겪게 된다.
따라서 VMware나 VirtualBox를 사용하는 학습자는 리눅스 VM을 생성하고, 거기에 도커 엔진을 설치하여 필요에 따라 SSH로 접속하는 것이 더 좋은 방법이지 않을까 생각된다.
이번 포스팅에서는 우분투 리눅스 서버 (20.04 LTS) 버전에 도커 엔진을 설치하는 방법을 설명하겠다.
우선 이번 포스팅은 우분투 서버 VM이 이미 준비가 되어 있다는 전제에서 설명하겠다. 만약 우분투 서버 VM을 만들 필요가 있다면 필자의 다른 포스팅을 참고하기 바란다.
리눅스에 도커 엔진을 설치하는 것은 도커 사이트에서 참조하여 설명하고 있다.
Ubutnu Server Linux Shell에서 다음 명령어를 입력한다.
Set up the Repository (도커 설치를 위한 저장소 추가)
1. Update the apt package index and install packages to allow apt to use a repository over HTTPS:
sudo apt-get update
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
실행
youngsoo@ubuntuvm:~$ sudo apt-get update
[sudo] password for youngsoo:
Hit:1 http://kr.archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://kr.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:3 http://kr.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:4 http://kr.archive.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:5 http://kr.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [2,036 kB]
Get:6 http://kr.archive.ubuntu.com/ubuntu focal-updates/main amd64 c-n-f Metadata [15.6 kB]
Get:7 http://kr.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [936 kB]
Get:8 http://kr.archive.ubuntu.com/ubuntu focal-updates/universe Translation-en [210 kB]
Get:9 http://kr.archive.ubuntu.com/ubuntu focal-updates/universe amd64 c-n-f Metadata [21.0 kB]
Get:10 http://kr.archive.ubuntu.com/ubuntu focal-security/main amd64 Packages [1,672 kB]
Get:11 http://kr.archive.ubuntu.com/ubuntu focal-security/main Translation-en [282 kB]
Get:12 http://kr.archive.ubuntu.com/ubuntu focal-security/main amd64 c-n-f Metadata [10.8 kB]
Get:13 http://kr.archive.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [1,138 kB]
Get:14 http://kr.archive.ubuntu.com/ubuntu focal-security/restricted Translation-en [162 kB]
Get:15 http://kr.archive.ubuntu.com/ubuntu focal-security/universe amd64 Packages [714 kB]
Get:16 http://kr.archive.ubuntu.com/ubuntu focal-security/universe Translation-en [130 kB]
Get:17 http://kr.archive.ubuntu.com/ubuntu focal-security/universe amd64 c-n-f Metadata [14.7 kB]
Fetched 7,678 kB in 5s (1,472 kB/s)
Reading package lists... Done
youngsoo@ubuntuvm:~$
youngsoo@ubuntuvm:~$ 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.
curl is already the newest version (7.68.0-1ubuntu2.12).
curl set to manually installed.
gnupg is already the newest version (2.2.19-3ubuntu2.2).
gnupg set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 41 not upgraded.
youngsoo@ubuntuvm:~$
2. Add Docker’s official GPG key:
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
실행
youngsoo@ubuntuvm:~$ sudo mkdir -p /etc/apt/keyrings
youngsoo@ubuntuvm:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
youngsoo@ubuntuvm:~$
3. Use the following command to set up the repository:
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
실행
youngsoo@ubuntuvm:~$ 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
youngsoo@ubuntuvm:~$
도커 엔진의 설치
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
실행
youngsoo@ubuntuvm:~$ sudo apt-get update
Get:1 https://download.docker.com/linux/ubuntu focal InRelease [57.7 kB]
Get:2 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages [17.7 kB]
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 75.4 kB in 1s (55.8 kB/s)
Reading package lists... Done
youngsoo@ubuntuvm:~$ 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 41 not upgraded.
Need to get 108 MB of archives.
After this operation, 449 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 https://download.docker.com/linux/ubuntu focal/stable amd64 containerd.io amd64 1.6.7-1 [28.1 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 slirp4netns amd64 0.4.3-1 [74.3 kB]
Get:4 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce-cli amd64 5:20.10.17~3-0~ubuntu-focal [40.6 MB]
Get:5 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce amd64 5:20.10.17~3-0~ubuntu-focal [21.0 MB]
Get:6 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce-rootless-extras amd64 5:20.10.17~3-0~ubuntu-focal [8,171 kB]
Get:7 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-compose-plugin amd64 2.6.0~ubuntu-focal [6,560 kB]
Get:8 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-scan-plugin amd64 0.17.0~ubuntu-focal [3,521 kB]
Fetched 108 MB in 11s (10.1 MB/s)
Selecting previously unselected package pigz.
(Reading database ... 71802 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.7-1_amd64.deb ...
Unpacking containerd.io (1.6.7-1) ...
Selecting previously unselected package docker-ce-cli.
Preparing to unpack .../2-docker-ce-cli_5%3a20.10.17~3-0~ubuntu-focal_amd64.deb ...
Unpacking docker-ce-cli (5:20.10.17~3-0~ubuntu-focal) ...
Selecting previously unselected package docker-ce.
Preparing to unpack .../3-docker-ce_5%3a20.10.17~3-0~ubuntu-focal_amd64.deb ...
Unpacking docker-ce (5:20.10.17~3-0~ubuntu-focal) ...
Selecting previously unselected package docker-ce-rootless-extras.
Preparing to unpack .../4-docker-ce-rootless-extras_5%3a20.10.17~3-0~ubuntu-focal_amd64.deb ...
Unpacking docker-ce-rootless-extras (5:20.10.17~3-0~ubuntu-focal) ...
Selecting previously unselected package docker-compose-plugin.
Preparing to unpack .../5-docker-compose-plugin_2.6.0~ubuntu-focal_amd64.deb ...
Unpacking docker-compose-plugin (2.6.0~ubuntu-focal) ...
Selecting previously unselected package docker-scan-plugin.
Preparing to unpack .../6-docker-scan-plugin_0.17.0~ubuntu-focal_amd64.deb ...
Unpacking docker-scan-plugin (0.17.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.17.0~ubuntu-focal) ...
Setting up containerd.io (1.6.7-1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service.
Setting up docker-compose-plugin (2.6.0~ubuntu-focal) ...
Setting up docker-ce-cli (5:20.10.17~3-0~ubuntu-focal) ...
Setting up pigz (2.4-1) ...
Setting up docker-ce-rootless-extras (5:20.10.17~3-0~ubuntu-focal) ...
Setting up docker-ce (5:20.10.17~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.15) ...
youngsoo@ubuntuvm:~$
도커의 설치 확인
(다음과 같은 메시지가 나오면 설치가 정상적으로 된 것이다.)
youngsoo@ubuntuvm:~$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:7d246653d0511db2a6b2e0436cfd0e52ac8c066000264b3ce63331ac66dca625
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/
youngsoo@ubuntuvm:~$
도커 설치 후 작업
도커를 매번 실행할 때 sudo 명령어를 주기가 번거롭기 때문에
youngsoo@ubuntuvm:~$ sudo groupadd docker
groupadd: group 'docker' already exists
youngsoo@ubuntuvm:~$ sudo usermod -aG docker $USER
youngsoo@ubuntuvm:~$
도커가 설치된 리눅스 VM을 재부팅한다.
'DevOps > DockerKubernetes' 카테고리의 다른 글
| 컨테이너와 Docker Host간의 파일 복사 (0) | 2022.08.11 |
|---|---|
| 가상화와 컨테이너의 차이는 무엇? (0) | 2022.08.11 |
| 도커 명령어 시작하기 (0) | 2022.08.11 |
| 도커의 가장 기초적인 이해 (0) | 2022.08.11 |
| Docker(Desktop)의 설치 (0) | 2022.08.10 |