Docker

[Docker] 엔진 설치 & 이미지 관련 명령

블루빔 2023. 11. 14. 19:30

목차
▶ Docker 엔진 설치
▶ Docker 이미지 pull
▶ Docker 이미지 확인
▶ Docker 이미지 build
Docker 이미지  delete

Docker 엔진 설치

rpm repository를 다운로드 

sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

♾️참고 링크


도커 엔진 설치 ( 최신 버전 )

sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

도커 시작 및 상태 확인 

systemctl start docker
systemctl status docker
systemctl enable docker

올바르게 설치되었는지 확인

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 이미지

컨테이너를 생성 시 도커 이미지가 필요합니다. (aws 기준 EC2 생성 시 머신이미지가 필요한 거처럼)  
도커 이미지는 ♾️ docker hub에서 제공하기도 하고 직접 커스텀하게 만들어 사용할 수도 있습니다.

Docker 이미지 pull

예시: Stackdriver-exporter 도커 이미지를 로컬 작업환경에 가져오기 )

docker pull prometheuscommunity/stackdriver-exporter:latest

참고 이미지 ⬇️

 

Docker 이미지 확인

docker images
----------------------------------------------------------------------------------------------------
REPOSITORY                                 TAG       IMAGE ID       CREATED        SIZE
prometheuscommunity/stackdriver-exporter   latest    cxxxxxxx964   6 weeks ago    24.3MB

 >> 이미지 세부정보 확인 

docker inspect #imageID

 

Docker 이미지 build

Dockerfile을 이용하여 도커 이미지를 커스텀하게 빌드할 수 있습니다. 

docker build #Dockerfile경로 -t #생성할 도커 이미지 네임

예시 : ( prometheus 도커 이미지를 커스텀하게 변경하여 빌드하기 ) 

Dockerfile 작성 예시
=======================================
FROM prom/prometheus

user root
run sed -i 's/UTC0/UTC\-9/g' /etc/localtime

USER       nobody
EXPOSE     9090
VOLUME     [ "/prometheus" ]
ENTRYPOINT [ "/bin/prometheus" ]
CMD        [ "--config.file=/etc/prometheus/prometheus.yml", \
             "--storage.tsdb.path=/prometheus", \
             "--web.console.libraries=/usr/share/prometheus/console_libraries", \
             "--web.console.templates=/usr/share/prometheus/consoles", \
             "--storage.tsdb.retention.time=365d", \
             "--web.enable-lifecycle", \
             "--log.level=debug"]
도커 이미지 빌드
====================================
docker build . -t custome-pormetheus-img

 

Docker 이미지 delete

도커 이미지를 삭제하려면 도커 이미지 ID 또는 도커 이미지네임을 알고 있어야 하므로 먼저 도커 이미지를 조회해야 합니다.  

예시: 

도커 이미지삭제 옵션은  rmi 이며 컨테이너 삭제 옵션은  rm 니다. 헷갈리지 마시길 ~ 

docker rmi #삭제이미지ID|#삭제이미지네임