Dockerfile 명령어 추가 정리

Pyro·2021년 8월 27일
0

Docker

목록 보기
7/7
  • ENV : 환경변수 설정
  • WORKDIR : 작업 디렉토리 할당
FROM ubuntu:18.04

# 부모 디렉토리
ENV DIRPARENT /parent

# 자식 디렉토리
ENV DIRCHILD child

# 작업 디렉토리 설정, 없으면 해당 디렉토리를 만든다.
WORKDIR /$DIRPARENT/$DIRCHILD

# 현재 디렉토리 출력
RUN ["pwd"]

# DOCKER_BUILDKIT=0 docker build -t dir .
  • USER : 유저 할당
  • LABEL : 이미지 버전 정보, 작성자 등의 레이블 지정
  • EXPOSE : 포트 할당
  • ARG : Dockerfile 내부의 변수 할당
  • SHELL : 기본 쉘 할당
FROM ubuntu:18.04

LABEL title="My Ubuntu"

ARG MESSAGE="complete"

RUN adduser --disabled-password --gecos "" ghojeong
RUN whoami

USER ghojeong
RUN whoami

RUN echo $MESSAGE

# DOCKER_BUILDKIT=0 docker build -t myubuntu .
  • ADD : 파일 및 디렉토리 추가
  • COPY : 파일 복사, ADD 보다 COPY 를 더 권장함
  • VOLUME : 볼륨 할당
FROM ubuntu:18.04

WORKDIR /html
ADD index.html .
RUN ["pwd"]
RUN ls -al

WORKDIR /inside-html
COPY index.html .
RUN ["pwd"]
RUN ls -al
RUN cat index.html

# DOCKER_BUILDKIT=0 docker build -t addcopy .
profile
dreams of chronic and sustained passion

0개의 댓글