FROM: 생성할 이미지의 베이스 이미지
MAINTAINER: 이미지를 생성한 개발자의 정보를 나타냄
LABEL: 이미지에 메타데이터를 추가 함 “키=값" 형태로 저장되며 이후 docker inspect 명령어로 이미지의 정보를 확인 할 수 있음
RUN 이미지를 만들기 위해 컨테이너 내부에서 명령어를 실행함
ADD: 로컬에 있는 파일을 이미지에 추가함
WORKDIR: 명령어를 실행할 디렉터리를 나타냄
EXPOSE: 이미지에서 노출할 포트를 설정함
CMD: 컨테이너가 시작 할 때 실행할 명령어를 설정함
작성 예시
FROM ubuntu:14.04
LABEL maintainer "asdf"
LABEL purpose="practice"
RUN apt-get update
RUN apt-get install apache2 -y
ADD egg.html /var/www/html
WORKDIR /var/www/html
RUN ["/bin/bash", "-c", "echo hello > test2.html"]
EXPOSE 80
CMD apachectl -DFOREGROUND
docker build -t egg:0.0 ./
컨테이너 실행
docker run -d -P --name eggserver egg:0.0
docker images --filter "label=purpose=practice"
빌드 컨텍스트
dockerignore 예시
# nano .dockerignore
test2.html
*.html
*/*.html
test.htm? ex) test.htmb, test.html, .... etc
예시
# nano Dockerfile2
FROM ubuntu:14.04
LABEL maintainer "chobe1 <chobe1@naver.com>"
RUN apt-get update
docker build --no-cache -t egg:0.0 ./
docker build --cache-from nginx -t egg:0.0
작성예시
FROM golang
ADD main.go /root
WORKDIR /root
RUN go build -o /root/mainApp /root/main.go
FROM alpine:latest
WORKDIR /root
# /root/mainApp 을 alpine:latest 이미지에 복사 from=0 첫번째 FROM 에서 빌드된 이미지의 최종상태
COPY --from=0 /root/mainApp .
CMD ["./mainApp"]
# 특정 단계의 이미지에 별도의 이름을 정의해 사용하는 경우
FROM golang as builder
ADD main.go /root
WORKDIR /root
RUN go build -o /root/mainApp /root/main.go
FROM alpine:latest
WORKDIR /root
COPY --from=builder /root/mainApp .
CMD ["./mainApp"]