Skip to content

Instantly share code, notes, and snippets.

@kamal-github
Created March 20, 2021 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamal-github/7d053fc45ffe4a226565c094feb705c7 to your computer and use it in GitHub Desktop.
Save kamal-github/7d053fc45ffe4a226565c094feb705c7 to your computer and use it in GitHub Desktop.
Docker file best practices
  1. order instruction by least to most frequent changing content
  2. Avoid COPY . (Copy only what is needed if possible)
  3. Don’t use latest tag, add a specific version
  4. Multi stage build -
    1. DRY
    2. small image size
    3. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment