From b90deff361cf54f35a02898113f832f9feadfa89 Mon Sep 17 00:00:00 2001 From: Ralph Bodenner Date: Wed, 10 Nov 2021 23:48:18 -0800 Subject: [PATCH] Clearer purpose and contents for .dockerignore I had to read the original paragraph a few times and search for docs on the file's purpose to understand what this step entailed. So here's another try at an explanation of what to do and why, with a hint about best practice. --- language/java/build-images.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/language/java/build-images.md b/language/java/build-images.md index 8a8eccb096..7e394e34db 100644 --- a/language/java/build-images.md +++ b/language/java/build-images.md @@ -153,7 +153,13 @@ CMD ["./mvnw", "spring-boot:run"] ### Create a `.dockerignore` file -To use a file in the build context, the Dockerfile refers to the file specified in an instruction, for example, a `COPY` instruction. To increase the performance of the build, and to exclude files and directories, we recommend that you create a `.dockerignore` file to the context directory. To improve the context load time, add a `target` directory within the `.dockerignore` file. +To increase the performance of the build, and as a general best practice, we recommend that you create a `.dockerignore` file in the same directory as the Dockerfile. For this tutorial, your `.dockerignore` file should contain just one line: + +``` +target +``` + +This line excludes the `target` directory, which contains output from Maven, from the Docker build context. The build context is what Docker commands like `RUN` refer to and it has to be created for every build, by packaging up any files not excluded by `.dockerignore`. There are many good reasons to carefully structure a `.dockerignore` file, but this one-line file is good enough for now. ## Build an image