Ubuntu에 Docker Engine 설치

Docker Engine은 컨테이너화된 응용 프로그램을 개발, 배포 및 실행하는 데 사용되는 강력한 플랫폼이다. 이 글에서는 Ubuntu 22.04 LTS 에서 Docker Engine을 설치하는 방법을 알아본다.

이전 버전 제거

Distro 관리자는 APT에서 Docker 패키지의 비공식 배포판을 제공한다. Docker 엔진의 공식 버전을 설치하려면 충돌할 수 있는 이전 패키지들을 제거하는 것이 좋다.

제거할 비공식 패키지는 다음과 같다.

  • docker.io
  • docker-compose
  • docker-compose-v2
  • docker-doc
  • podman-docker

또한 Docker 엔진은 containerdrunc 에 의존한다. Docker 엔진은 이러한 의존성을 containerd.io 번들로 묶는다. 만약 containerd 또는 runc가 이전에 설치되어 있다면, Docker 엔진과 함께 번들로 제공되는 버전들과의 충돌을 방지하기 위해 제거 하는 것이 좋다.

다음의 명령어를 실행하여 충돌하는 모든 패키지를 제거한다.

$ for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done

Docker Engine 설치

처음으로 Docker 엔진을 설치하기 전에 Docker 저장소를 설정해야 한다. 그런 다음 Repository에서 Docker를 설치하고 업데이트할 수 있다.

Docker apt저장소를 설정

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add the repository to Apt sources:
echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

Docker 패키지 설치

최신 버전을 설치하려면 아래를 실행한다.

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

특정 버전을 설치하려면 먼저 저장소에서 사용 가느한 버전을 확인한다.

$ apt-cache madison docker-ce | awk '{ print $3 }'
...
5:24.0.0-1~ubuntu.22.04~jammy
5:23.0.6-1~ubuntu.22.04~jammy
...

설치하려는 버전을 선택하고 설치한다. (예: 5:24.0.0-1~ubuntu.22.04~jammy)

$ sudo apt-get install docker-ce=5:24.0.0-1~ubuntu.22.04~jammy docker-ce-cli=5:24.0.0-1~ubuntu.22.04~jammy containerd.io docker-buildx-plugin docker-compose-plugin

이미지 실행하여 Docker Engine 설치 확인

다음 명령은 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/

Docker 엔진 제거

Docker 엔진, CLI, Containerd 및 Docker Compose 패키지를 제거한다.

$ sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras

호스트의 이미지, 컨테이너, 볼륨 또는 사용자 지정 구성 파일은 자동으로 제거되지 않기 때문에 모든 이미지, 컨테이너 및 볼륨을 삭제하려면 다음을 수행하여 제거해 준다.

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

참고

답글 남기기