Instructions
Command | Description | etc |
FROM | 이미지 불러오기 | |
ENV | 환경 변수 값 지정 | |
WORKDIR | 컨테이너 파일 시스템에 해당 디렉토리 생성 및 작업 디렉터리로 지정 | 단순 copy 작업 |
COPY | 파일/디렉토리를 이미지의 파일 시스템에 복사 | |
ADD | New file, Dir, remote file URL을 복사하여 경로 대상 이미지의 파일 시스템에 추가 | 압축 해제, URL 지원 |
CMD | 컨테이너 실행 시 입력되는 커맨드 | only one in Dockerfile |
EXPOSE | 컨테이너 포트 번호 지정 | |
ENTRYPOINT | 컨테이너 실행 시 정의된 커맨드 실행 | 주로 변하지 않는 값을 지정함 |
LABEL | 이미지에 메타데이터 추가 | |
VOLUME | 지정한 이름으로 mount point 생성 및 Volume 생성 | |
HEALTHCHECK | 컨테이너 내부에서 실행되는 인스트럭션 컨테이너의 상태를 출력받기 위해 사용 |
only one in Dockerfile |
STOPSIGNAL | 종료할 컨테이너로 전송할 시스템 호출 신호 설정 | |
USER | 사용자 이름(or UID) 또는 사용자 그룹 (or GID)설정 | |
RUN | 이미지 빌드 과정에서 필요한 명령어 실행 | e.g. apt install, ... |
ARG | Build-time variables로 build에서 정의되는 변수 | --build-arg ❗️docker history로 확인할 수 있으므로 암호는 할당하지 않는다 |
SHELL | Default shell overridden | zsh, csh, tcsh, posershell 사용 가능 |
ONBUILD | 해당 이미지에서 파생된 하위 이미지에서 실행되는 Trigger | |
MAINTAINER | 생성된 이미지의 Author field 설정 |
Example
## FROM (default tag: latest)
FROM <image>
FROM <image>:<tag>
FROM <image>@<digest>
## ENV
ENV <key> <value>
ENV <key>=<value>
## WORKDIR
WORKDIR <path>
## COPY
COPY <src> <dest>
## ADD
ADD <복사할 파일 경로> <이미지에서 파일이 위치할 경로>
## CMD
CMD ["<executable>","<param1>","<param2>"] ➤ (exec form, this is the preferred form)
CMD ["<param1>","<param2>"] ➤ (as default parameters to ENTRYPOINT)
CMD <command> <param1> <param2> ➤ (shell form)
## EXPOSE
EXPOSE <port>
## ENTRYPOINT
ENTRYPOINT ["<executable>", "<param1>", "<param2>"] ➤ (exec form, preferred)
ENTRYPOINT <command> <param1> <param2> ➤ (shell form)
## LABEL
LABEL <key>=<value>
## VOLUME
VOLUME <path>
## HEALTHCHECK
HEALTHCHECK [<options>] CMD <command> ➤ (check container health by running a command inside the container)
HEALTHCHECK NONE ➤ (disable any healthcheck inherited from the base image)
# options
--interval=<duration> (default 30s)
--timeout=<duration> (default 30s)
--retries=<number> (default 3)
# Exit code
0: success, 컨테이너가 정상적이고 사용 가능한 상태
1: unhealthy, 컨테이너가 올바르게 작동하지 않는 상태
2: reserved, (do not use this exit code)
## STOPSIGNAL
STOPSIGNAL <signal>
## USER
USER <username>
## RUN
RUN <command>
RUN ["<executable>", "<param1>", "<param2>"] ➤ (exec form)
## ARG
ARG <name>
# predefined ARG variables
HTTP_PROXY and http_proxy
HTTPS_PROXY and https_proxy
FTP_PROXY and ftp_proxy
NO_PROXY and no_proxy
## SHELL
SHELL ["<executable>", "<param1>", "<param2>"]
## ONBUILD
ONBUILD <Dockerfile INSTRUCTION>
## MAINTAINER
MAINTAINER <name>
Reference
Dockerfile reference
docs.docker.com
Best practices for writing Dockerfiles
docs.docker.com
Dockerfile Cheat Sheet - Kapeli
Usage: FROM FROM : FROM @ Information: FROM must be the first non-comment instruction in the Dockerfile. FROM can appear multiple times within a single Dockerfile in order to create multiple images. Simply make a note of the last image ID output by the com
kapeli.com
'인프라 > 도커' 카테고리의 다른 글
[Docker] docker-compose.yml (0) | 2023.03.24 |
---|---|
[Docker] 도커 컴포즈 명령어 정리 (0) | 2023.03.24 |
[Docker] 도커 명령어 정리 (0) | 2023.03.23 |
[Docker] Shortcut (0) | 2023.03.23 |