Docker 이미지의 시작 명령 선택

Docker 입문

Tim Sangster

Software Engineer @ DataCamp

시작 명령이란?

hello-world 이미지는 텍스트를 출력하고 종료합니다.

docker run hello-world
Hello from Docker!

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon created a new container from the hello-world image which runs the
    executable that produces the output you are currently reading.
 3. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.
Docker 입문

시작 명령이란?

python이 포함된 이미지는 시작 시 python을 실행할 수 있습니다.

docker run python3-sandbox
Python 3.10.6 (main, Nov  2 2022, 18:53:38) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
...
....
>>> exit()
repl@host:/#
Docker 입문

시작 시 셸 명령 실행

CMD <shell-command>

CMD 지시어:

  • 이미지를 시작할 때 실행됩니다.
  • 이미지 크기를 늘리지 않습니다.
  • 빌드 시간에 영향을 주지 않습니다.
  • 여러 개면 마지막 것만 적용됩니다.
Docker 입문

일반적 사용 예

워크플로를 실행하거나 외부 연결을 수락하는 애플리케이션 시작.

CMD python3 my_pipeline.py
CMD postgres

여러 애플리케이션을 순차로 시작하는 스크립트 실행

CMD start.sh
CMD python3 start_pipeline.py
Docker 입문

언제 종료되나요?

$$

  • hello-world 이미지 -> 텍스트 출력 후
  • 데이터베이스 이미지 -> DB가 종료되면

$$

일반적인 이미지는 더 일반적인 시작 명령이 필요합니다.

  • Ubuntu 이미지 -> 셸을 닫으면
Docker 입문

기본 시작 명령 재정의

이미지 시작

docker run <image>

사용자 지정 시작 명령으로 시작

docker run <image> <shell-command>

사용자 지정 시작 명령으로 대화형 시작

docker run -it <image> <shell-command>
docker run -it ubuntu bash
Docker 입문

요약

용도 Dockerfile 지시어
이미지에서 컨테이너가 시작될 때 실행할 셸 명령 추가 CMD <shell-command>

용도 셸 명령
이미지에 설정된 CMD 재정의 docker run <image> <shell-command>
CMD를 재정의하고 대화형 실행 docker run -it <image> <shell-command>
Docker 입문

연습해 봅시다!

Docker 입문

Preparing Video For Download...