Docker 를 Ubuntu 22.04에 설치하는 방법

Docker는 OS 수준 가상화를 사용하여 컨테이너라는 패키지로 소프트웨어를 제공하는 오픈 소스 플랫폼입니다.  컨테이너는 애플리케이션이 한 컴퓨팅 환경에서 다른 컴퓨팅 환경으로 빠르고 안정적으로 실행되도록 코드와 모든 종속성을 패키징하는 소프트웨어 단위입니다.


이 가이드에서는 Ubuntu 22.04 LTS에 Docker를 설치하는 방법을 배웁니다. 

초기 설정

패키지를 사용 가능한 최신 버전으로 업데이트하여 시작하십시오.

sudo apt update
sudo apt upgrade

Docker Install – 도커 설치

공식 Docker 리포지토리에서 최신 버전의 Docker를 설치해야 합니다. 공식 Ubuntu 리포지토리에도 Docker 설치 패키지가 있지만 최신 버전이 아닐 수 있습니다.

Docker 설치를 시작하겠습니다.

HTTPS를 통해 패키지를 사용할 수 있는 일부 패키지를 설치합니다.

sudo apt install apt-transport-https ca-certificates curl software-properties-common

Docker 저장소의 GPG 키를 추가하십시오.

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

이제 Ubuntu 22.04( jammy) 의 Docker 저장소를 apt소스에 추가하십시오.

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

공식 Docker 저장소에서 Docker를 설치하도록 패키지 색인을 업데이트하고 서버를 설정하십시오.

sudo apt update
sudo apt-cache policy docker-ce
docker-ce:
  Installed: 5:20.10.21~3-0~ubuntu-jammy
  Candidate: 5:20.10.21~3-0~ubuntu-jammy
  Version table:
 *** 5:20.10.21~3-0~ubuntu-jammy 500
        500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
        100 /var/lib/dpkg/status
     5:20.10.20~3-0~ubuntu-jammy 500
        500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
     5:20.10.19~3-0~ubuntu-jammy 500
        500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages

Docker가 설치되고 부팅 시 프로세스가 시작되도록 활성화 합니다.
Docker의 상태를 확인하려면 다음 명령을 사용할 수 있습니다.

sudo apt install docker-ce
sudo systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-11-16 19:55:37 UTC; 18min ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 15323 (dockerd)
      Tasks: 8
     Memory: 21.8M
        CPU: 433ms
     CGroup: /system.slice/docker.service
             └─15323 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Nov 16 19:55:37 dk dockerd[15323]: time="2022-11-16T19:55:37.583569730Z" level=info msg="scheme \"unix\" not registered, fallback to def>
Nov 16 19:55:37 dk dockerd[15323]: time="2022-11-16T19:55:37.583693568Z" level=info msg="ccResolverWrapper: sending update to cc: {[{uni>
Nov 16 19:55:37 dk dockerd[15323]: time="2022-11-16T19:55:37.583801307Z" level=info msg="ClientConn switching balancer to \"pick_first\">
Nov 16 19:55:37 dk dockerd[15323]: time="2022-11-16T19:55:37.650144270Z" level=info msg="Loading containers: start."
Nov 16 19:55:37 dk dockerd[15323]: time="2022-11-16T19:55:37.830623930Z" level=info msg="Default bridge (docker0) is assigned with an IP>
Nov 16 19:55:37 dk dockerd[15323]: time="2022-11-16T19:55:37.911732352Z" level=info msg="Loading containers: done."
Nov 16 19:55:37 dk dockerd[15323]: time="2022-11-16T19:55:37.937397022Z" level=info msg="Docker daemon" commit=3056208 graphdriver(s)=ov>
Nov 16 19:55:37 dk dockerd[15323]: time="2022-11-16T19:55:37.937521102Z" level=info msg="Daemon has completed initialization"
Nov 16 19:55:37 dk dockerd[15323]: time="2022-11-16T19:55:37.963187641Z" level=info msg="API listen on /run/docker.sock"
Nov 16 19:55:37 dk systemd[1]: Started Docker Application Container Engine.

Docker에 대한 Sudo 권한 구성

그만큼docker명령기본적으로 루트 사용자 로만 실행할 수 있습니다 . 실행해야 하는 경우그만큼docker명령없이스도, docker 그룹 에 사용자 이름을 추가해야 합니다 .

sudo usermod -aG USERNAME

이제 SSH를 다시 ​​시작하거나 새 터미널을 열어 변경 사항을 확인하십시오.

docker지금부터 sudo 없이 명령 을 사용합니다 .

Docker 명령 사용

Docker에 대한 시스템 정보를 보려면.

docker info

Docker 이미지 다운로드

docker run hello-world

얻은 출력이 아래와 유사하면 Docker Hub에서 이미지에 액세스하고 다운로드할 수 있습니다.

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:faa03e786c97f07ef34423fccceeec2398ec8a5759259f94d99078f264e9d7af
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/

아래 명령을 실행하여 다운로드한 이미지를 확인합니다.

docker image

Docker 기본 명령어

Docker를 사용하기 시작하면 많은 활성 및 비활성 컨테이너가 생깁니다.

모든 활성 컨테이너를 보려면 다음 명령을 사용하십시오.

docker ps

활성 및 비활성 컨테이너를 모두 보려면 아래 명령을 사용하십시오.

docker ps -a

최신 컨테이너를 보려면

docker ps -l

도커 컨테이너를 시작하려면 docker start명령 다음에 컨테이너 ID 또는 컨테이너 이름을 사용하십시오.

docker start container-id/name

마찬가지로 실행 중인 컨테이너를 중지하려면 docker stop명령 다음에 컨테이너 ID 또는 컨테이너 이름을 사용할 수 있습니다.

docker stop container-id/name

컨테이너가 더 이상 필요하지 않은 경우 다음을 사용하여 컨테이너를 제거할 수 있습니다.그만큼docker rm팔로우컨테이너 ID 또는 컨테이너 이름으로.

docker rm container-id/name

대화식 쉘에 들어가려면 다음 명령을 사용할 수 있습니다.

docker run -it container-id/name

셸 내부에 명령을 수동으로 설치할 수 있습니다.

docker 명령에 대한 자세한 내용은 명령을 사용하십시오 

docker run help

Leave a Reply

Your email address will not be published. Required fields are marked *