·터미널 명령어

docker build

패키지·런타임

쓰는 꼴

docker build -t <name>:<tag> [-f <Dockerfile>] <context>

Dockerfile로 이미지를 만듭니다 — 끝의 점은 데몬에게 보낼 빌드 컨텍스트라서 폴더가 크면 빌드가 느려지고(.dockerignore로 줄입니다), COPY는 그 컨텍스트 안의 파일만 볼 수 있습니다.

자주 쓰는 옵션

옵션
-t <name>:<tag>name the image; without it you only get an id
-f <file>use a Dockerfile that is not ./Dockerfile
--no-cacherebuild every layer
--build-arg KEY=valuepass an ARG into the build
--target <stage>stop at one stage of a multi-stage file
--platform linux/amd64build for another architecture
--progress=plainfull log output instead of the collapsed view

예시

docker build -t myapp:1.0 .

builds from ./Dockerfile with the current folder as context

docker build -f docker/Dockerfile.dev -t myapp:dev .

another Dockerfile, same context

docker build --platform linux/amd64 -t myapp:1.0 .

an x86 image built on an Apple Silicon Mac

무엇을 어디에 넣는지가 문제입니다. 프로젝트 안인지 시스템 전체인지 먼저 정하세요.

읽는 방법

  • 대괄호 [ ]는 넣어도 되고 안 넣어도 되는 자리입니다.
  • 점 셋 …은 여러 개를 이어 쓸 수 있다는 뜻입니다.
  • 옵션은 대소문자를 가립니다 — -r과 -R이 다른 명령도 있습니다.

자주 묻는 것

Q. docker build은 무엇을 하나요?

Dockerfile로 이미지를 만듭니다 — 끝의 점은 데몬에게 보낼 빌드 컨텍스트라서 폴더가 크면 빌드가 느려지고(.dockerignore로 줄입니다), COPY는 그 컨텍스트 안의 파일만 볼 수 있습니다.

Q. 어떻게 치나요?

docker build -t <name>:<tag> [-f <Dockerfile>] <context> — 대괄호는 생략할 수 있는 자리입니다.

Q. 옵션은 몇 개나 자주 쓰나요?

여기 정리한 것은 7개입니다. 전체 목록은 man docker에 있습니다. 이 명령은 패키지·런타임 갈래입니다.

같이 보는 명령

man 페이지: man docker-build