diff --git a/content/build/building/best-practices.md b/content/build/building/best-practices.md index 8d6956f532..d2c6171cad 100644 --- a/content/build/building/best-practices.md +++ b/content/build/building/best-practices.md @@ -107,7 +107,15 @@ Also consider [pinning base image versions](#pin-base-image-versions). To exclude files not relevant to the build, without restructuring your source repository, use a `.dockerignore` file. This file supports exclusion patterns -similar to `.gitignore` files. For information on creating one, see +similar to `.gitignore` files. + +For example, to exclude all files with the `.md` extension: + +```plaintext +*.md +``` + +For information on creating one, see [Dockerignore file](../../build/building/context.md#dockerignore-files). ## Create ephemeral containers @@ -312,13 +320,39 @@ Split long or complex `RUN` statements on multiple lines separated with backslashes to make your Dockerfile more readable, understandable, and maintainable. +For example, you can chain commands with the `&&` operator, and use +use escape characters to break long commands into multiple lines. + +```dockerfile +RUN apt-get update && apt-get install -y \ + package-bar \ + package-baz \ + package-foo +``` + +By default, backslash escapes a newline character, but you can change it with +the [`escape` directive](../../reference/dockerfile.md#escape). + +You can also use here documents to run multiple commands without chaining them +with a pipeline operator: + +```dockerfile +RUN <