본문 바로가기
DevOps/DockerKubernetes

우분투 리눅스에서 도커 설치

by 계영수 2022. 9. 4.
728x90

1.  Update the apt package index and install packages to allow apt to use a repository over HTTPS:

vagrant@ubuntu-focal:~$ sudo apt-get update
Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease                                                   
Get:2 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]                                
Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:5 http://security.ubuntu.com/ubuntu focal-security/main amd64 c-n-f Metadata [11.0 kB]
Get:6 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [717 kB]
Get:7 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages [8628 kB]
Get:8 http://security.ubuntu.com/ubuntu focal-security/universe Translation-en [131 kB]
Get:9 http://security.ubuntu.com/ubuntu focal-security/universe amd64 c-n-f Metadata [14.8 kB]
Get:10 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [22.2 kB]         
Get:11 http://security.ubuntu.com/ubuntu focal-security/multiverse Translation-en [5376 B]     
Get:12 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 c-n-f Metadata [508 B]  
Get:13 http://archive.ubuntu.com/ubuntu focal/universe Translation-en [5124 kB]                                                                                                          
Get:14 http://archive.ubuntu.com/ubuntu focal/universe amd64 c-n-f Metadata [265 kB]                                                                                                     
Get:15 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [144 kB]                                                                                                         
Get:16 http://archive.ubuntu.com/ubuntu focal/multiverse Translation-en [104 kB]                                                                                                         
Get:17 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 c-n-f Metadata [9136 B]                                                                                                   
Get:18 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [2072 kB]                                                                                                      
Get:19 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 c-n-f Metadata [15.8 kB]                                                                                                
Get:20 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [943 kB]                                                                                                   
Get:21 http://archive.ubuntu.com/ubuntu focal-updates/universe Translation-en [213 kB]                                                                                                   
Get:22 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 c-n-f Metadata [21.2 kB]                                                                                            
Get:23 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 Packages [24.4 kB]                                                                                                
Get:24 http://archive.ubuntu.com/ubuntu focal-updates/multiverse Translation-en [7336 B]                                                                                                 
Get:25 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 c-n-f Metadata [588 B]                                                                                            
Get:26 http://archive.ubuntu.com/ubuntu focal-backports/main amd64 Packages [45.6 kB]                                                                                                    
Get:27 http://archive.ubuntu.com/ubuntu focal-backports/main Translation-en [16.3 kB]                                                                                                    
Get:28 http://archive.ubuntu.com/ubuntu focal-backports/main amd64 c-n-f Metadata [1420 B]                                                                                               
Get:29 http://archive.ubuntu.com/ubuntu focal-backports/restricted amd64 c-n-f Metadata [116 B]                                                                                          
Get:30 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 Packages [23.9 kB]                                                                                                
Get:31 http://archive.ubuntu.com/ubuntu focal-backports/universe Translation-en [16.0 kB]                                                                                                
Get:32 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 c-n-f Metadata [860 B]                                                                                            
Get:33 http://archive.ubuntu.com/ubuntu focal-backports/multiverse amd64 c-n-f Metadata [116 B]                                                                                          
Fetched 18.9 MB in 1min 1s (308 kB/s)                                                                                                                                                    
Reading package lists... Done
vagrant@ubuntu-focal:~$

 

vagrant@ubuntu-focal:~$ 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.13).
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 1 not upgraded.
vagrant@ubuntu-focal:~$

2. Add Docker’s official GPG key:

vagrant@ubuntu-focal:~$ sudo mkdir -p /etc/apt/keyrings
vagrant@ubuntu-focal:~$  curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
vagrant@ubuntu-focal:~$

3. Use the following command to set up the repository:

vagrant@ubuntu-focal:~$ 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
vagrant@ubuntu-focal:~$

4. 도커 설치

vagrant@ubuntu-focal:~$ 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.9 kB]
Hit:3 http://archive.ubuntu.com/ubuntu focal InRelease                                                   
Hit:4 http://security.ubuntu.com/ubuntu focal-security InRelease                                         
Hit:5 http://archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:6 http://archive.ubuntu.com/ubuntu focal-backports InRelease
Fetched 75.6 kB in 2s (50.0 kB/s)
Reading package lists... Done
vagrant@ubuntu-focal:~$  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 1 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.8-1 [28.1 MB]
Get:2 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:3 http://archive.ubuntu.com/ubuntu focal/universe amd64 pigz amd64 2.4-1 [57.4 kB]   
Get:4 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce amd64 5:20.10.17~3-0~ubuntu-focal [21.0 MB]
Get:5 http://archive.ubuntu.com/ubuntu focal/universe amd64 slirp4netns amd64 0.4.3-1 [74.3 kB]
Get:6 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce-rootless-extras amd64 5:20.10.17~3-0~ubuntu-focal [8171 kB]
Get:7 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-compose-plugin amd64 2.6.0~ubuntu-focal [6560 kB]
Get:8 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-scan-plugin amd64 0.17.0~ubuntu-focal [3521 kB]
Fetched 108 MB in 2s (65.9 MB/s)                                                 
Selecting previously unselected package pigz.
(Reading database ... 63500 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.8-1_amd64.deb ...
Unpacking containerd.io (1.6.8-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.8-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.17) ...
vagrant@ubuntu-focal:~$

5. 도커가 잘 설치되었는지 확인

vagrant@ubuntu-focal:~$  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/

vagrant@ubuntu-focal:~$

6.  도커 그룹에 사용자 추가

vagrant@ubuntu-focal:~$ sudo groupadd docker
groupadd: group 'docker' already exists
vagrant@ubuntu-focal:~$ sudo usermod -aG docker $USER
vagrant@ubuntu-focal:~$

7. 재부팅

728x90