Skip to content

Instantly share code, notes, and snippets.

@christophemarois
Last active September 21, 2023 15:49
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 christophemarois/5ba974af8810003d3320198b4c7c200a to your computer and use it in GitHub Desktop.
Save christophemarois/5ba974af8810003d3320198b4c7c200a to your computer and use it in GitHub Desktop.
Docker Cheatsheet

Run a local Dockerfile with a local .env file

docker build \

Show complete log

--progress=plain \

Nested dockerfile, useful for monorepos when we want to preserve CWD

--file Dockerfile.p-airsync \

tag can be anything

-t p-airsync:a \

CWD for Docker build, in a monorepo this should be repo root

.

docker build \
  # Show complete log
  --progress=plain \
  # Nested dockerfile, useful for monorepos when we want to preserve CWD
  --file nested/a/Dockerfile \
  # tag can be anything
  -t nested:a \
  # load .env from file if they're needed for build
  $(for i in `cat nested/a/.env`; do out+="--build-arg $i " ; done; echo $out;out="") \
  # CWD for Docker build, in a monorepo this should be repo root
  .

docker run \
  # Automatically remove the container when it exits
  --rm \
  # Map all inside ports to the host interface
  -P \
  # L
  --env-file nested/a/.env
  $TAG_NAME

If you want to debug a failing build

  • ensure --progress=plain is on
  • use log commands, e.g. RUN ls -r
  • bypass failing commands with || true if needed
  • end with an empty CMD
  • sh into container with docker run -it $TAG_NAME sh

If you want to log a filelist with size

RUN du -sh -- * | sort -h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment