[Docker] Ubuntu에 Docker 설치하기

qewr·2023년 1월 1일
0

Docker

목록 보기
1/4

Ubuntu에 Docker 설치하기

OS 요구사항

도커를 설치하기 위해서는 요구되는 Ubuntu의 버전은 다음과 같다. 하단의 목록 중에 자신이 사용하는 버전이 없다면 도커 엔진 설치가 불가능하다.

  • Ubuntu Kinetic 22.10
  • Ubuntu Jammy 22.04 (LTS)
  • Ubuntu Focal 20.04 (LTS)
  • Ubuntu Bionic 18.04 (LTS)

이전 버전 삭제하기

혹시 기존에 도커가 설치되어 있다면 먼저 삭제해준다. 도커를 삭제할 때 저장된 이미지나 컨테이너 등은 삭제되지 않으므로 데이터가 담겨있는 폴더도 같이 삭제해준다.

sudo apt remove docker docker-engine docker.io containerd runc
sudo apt purge docker-ce docker-ce-cli containerd.io docker-compose-plugin

sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

설치하기

도커를 설치하는 여러가지 방법이 있지만 여기서는 Repository를 이용하는 방법을 사용할 것이다.

Docker repository 설정

사용중인 패키지를 최신 버전으로 업그레이드한다.

sudo apt-get update && upgrade

HTTPS를 통해 레포지토리를 사용할 수 있도록 필요한 패키지를 설치한다.

sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

Docker 공식 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

Docker 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

Docker Engine 설치

최신 버전 설치

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

특정 버전 설치

레포지토리에서 사용 가능한 버전이 무엇이 있는지 확인한다.

$ apt-cache madison docker-ce | awk '{ print $3 }'

5:20.10.22~3-0~ubuntu-jammy
5:20.10.21~3-0~ubuntu-jammy
5:20.10.20~3-0~ubuntu-jammy
5:20.10.19~3-0~ubuntu-jammy
5:20.10.18~3-0~ubuntu-jammy
5:20.10.17~3-0~ubuntu-jammy
5:20.10.16~3-0~ubuntu-jammy
5:20.10.15~3-0~ubuntu-jammy
5:20.10.14~3-0~ubuntu-jammy
5:20.10.13~3-0~ubuntu-jammy

다운로드 받고 싶은 버전을 정하면 해당 버전으로 다운로드한다.

VERSION_STRING=5:20.10.22~3-0~ubuntu-jammy

sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-compose-plugin

Docker 설치 확인

도커가 정상적으로 설치되었는지 확인하기 위해 hello-world라는 이미지를 이용하여 컨테이너를 만들어본다. 정상적으로 동작한다면 확인 메시지를 남기고 컨테이너는 종료될 것이다.

$ sudo docker run hello-world

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/

🪅참고자료

0개의 댓글