- order instruction by least to most frequent changing content
- Avoid COPY . (Copy only what is needed if possible)
- Don’t use latest tag, add a specific version
- Multi stage build -
- DRY
- small image size
- Build different image for test/run/lint from base buiilt image
FROM image_or_stage AS stage_name
docker build —target=stage name
For building only the specific stage with all of its dependent stage
// default var flavour
ARG flavour alpine
FROM <> as builder
…
…
FROM <>-$flavour AS release
COPY —from=builder ….
$docker build --target=release —build-args flavour=jessie