본문 바로가기

가상 머신/Docker

[ Docker ] hello-world 실행하기

반응형

Docker를 설치한 후 hello-world 이미지를 실행하려면 다음 단계를 따르면 됩니다.


1. Docker 설치

Docker가 설치되어 있지 않다면, 아래 명령을 사용하여 설치합니다.

Ubuntu에서 Docker 설치

sudo apt update
sudo apt install docker.io -y
sudo systemctl enable docker
sudo systemctl start docker

설치 확인

docker --version

출력 예:

Docker version 20.10.25, build abcdef

2. hello-world 이미지 실행

Docker 설치 후 hello-world 이미지를 실행합니다.

명령어

docker run hello-world -it ubuntu bash

3. 결과 확인

hello-world 이미지를 처음 실행하면 다음 과정이 진행됩니다:

  1. Docker는 hello-world 이미지를 로컬에서 찾습니다.
    • 이미지가 없으면 Docker Hub에서 자동으로 다운로드합니다.
  2. 이미지를 실행하고 테스트 메시지를 출력합니다.

출력 예:

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

4. 실행 확인

docker images 명령으로 다운로드된 이미지를 확인할 수 있습니다.

명령어

docker images

출력 예:

REPOSITORY      TAG       IMAGE ID       CREATED        SIZE
hello-world     latest    d1165f221234   6 weeks ago    13kB

5. 문제 해결

문제 1: 권한 오류

  • docker run 실행 시 다음 오류가 발생할 수 있습니다:
  Got permission denied while trying to connect to the Docker daemon socket
  • 해결 방법: 현재 사용자를 docker 그룹에 추가.
  sudo usermod -aG docker $USER
  newgrp docker

문제 2: Docker 서비스 실행 안 됨

  • Docker 데몬이 실행 중인지 확인:
  sudo systemctl status docker
  • 실행되지 않았다면 시작:
  sudo systemctl start docker

요약

  1. Docker 설치 확인.
  2. docker run hello-world 명령 실행.
  3. 정상 작동 확인 후, 다음 단계를 진행.

이 과정을 통해 Docker 설치와 실행이 정상적으로 작동하는지 확인할 수 있습니다.

반응형