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.
This commit is contained in:
Ralph Bodenner 2021-11-10 23:48:18 -08:00 committed by GitHub
parent ac62c90284
commit b90deff361
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -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