귀염둥이의 메모

[Docker] Docker 설치, hello-world (CentOS 7 환경) 본문

Infra & Devops/Docker

[Docker] Docker 설치, hello-world (CentOS 7 환경)

겸둥이xz 2021. 9. 15. 10:01
반응형

CentOS 7 - Docker 설치

참조 : https://docs.docker.com/engine/install/centos/

  • docker-ce : 도커 엔진
  • docker-ce-cli : 엔진 명령 컨트롤 도구
  • containerd.io : 컨테이너 서비스 (실제로 컨테이너를 쓸 수 있는 서비스)

 

실행 및 설정

 

sudo systemctl start docker.service
sudo systemctl enable docker.service
sudo usermod -aG docker user  		➡️ user 사용자 docker 그룹에 추가

docker --version

 

hello-world 실행

docker container run <Docker 이미지명> <실행할 명령>
ex) docker container run ubuntu:latest /bin/echo 'Hello world'
➡️ Ubuntu 이미지 바탕으로 Docker 컨테이너를 작성 및 실행한 후, 컨테이너 안에서 "Hello world" 출력
docker run hello-world

Unable to find image 'hello-world:latest' locally   🐳 로컬에서는 못찾았다, latest는 기본값
latest: Pulling from library/hello-world	    🐳 도커 허브에서 가져옴
b8dfde127a29: Pull complete
Digest: sha256:7d91b69e04a9029b99f3585aaaccae2baa80bcf318f4a5d2165a9898cd2dc0a1
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/

 

Ubuntu에서 hello world 출력

docker run ubuntu:latest /bin/echo 'Hello world'

Unable to find image 'ubuntu:latest' locally 	🐳 저장된 이미지 없음, Pull
latest: Pulling from library/ubuntu
35807b77a593: Pull complete
Digest: sha256:9d6a8699fb5c9c39cf08a0871bd6219f0400981c570894cd8cbea30d3424a31f
Status: Downloaded newer image for ubuntu:latest
Hello world
------------- Hello world 출력 후 컨테이너 종료 됨


docker run ubuntu:latest cat /etc/os-release

🐳 PULL 없이 바로 실행, 이미 받아왔기 때문에

NAME="Ubuntu"
VERSION="20.04.3 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.3 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
  • docker run 명령을 실행하면 Docker 컨테이너의 바탕이 되는 Ubuntu의 Docker 이미지가 로컬 환경에 있는지 확인
  • 로컬 환경에 없다면 Docker 리포지토리에서 Docker 이미지를 다운한다
  • 'ubuntu:latest'는 최신 버전 이미지(latest)를 취득한다는 뜻, 'ubuntu'라고 입력하면 default 값으로 latest 적용
  • 두 번째 실행부터는 로컬 환경에 다운로된 이미지를 바탕으로 컨테이너를 시작

 

docker version (자세한 버전 확인)

  • 도커의 버전, Go 언어 버전, OS, 아키텍처를 확인 가능

 

 

docker system info (실행환경 상세 설정)

  • 도커 실행 환경의 상세 설정이 표시된다

 

 

docker system df (디스크 이용 상황)

  • 도커가 사용하고 있는 디스크의 이용 상황이 표시된다
  • -v 옵션을 이용하면 상세 정보를 확인 가능
반응형
Comments