From fc9025459a185f1668290d2cae5244cfcea8ac25 Mon Sep 17 00:00:00 2001 From: Dominik Mahnkopf <22577070+dmahnkopf@users.noreply.github.com> Date: Tue, 2 Jun 2020 22:07:07 +0200 Subject: [PATCH] Add .dockerignore for node_modules & explanation --- .../image-building-best-practices/index.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/tutorial/image-building-best-practices/index.md b/docs/tutorial/image-building-best-practices/index.md index 65f1360..02c5b84 100644 --- a/docs/tutorial/image-building-best-practices/index.md +++ b/docs/tutorial/image-building-best-practices/index.md @@ -79,6 +79,21 @@ a change to the `package.json`. Make sense? CMD ["node", "/app/src/index.js"] ``` +1. Create a file named `.dockerignore` in the same folder as the Dockerfile with the following contents. + + ```ignore + node_modules + ``` + + `.dockerignore` files are an easy way to selectively copy only image relevant files. + You can read more about this + [here](https://docs.docker.com/engine/reference/builder/#dockerignore-file). + In this case, the `node_modules` folder should be omitted in the second `COPY` step because otherwise, + it would possibly overwrite files which were created by the command in the `RUN` step. + For further details on why this is recommended for Node.js applications and other best practices, + have a look at their guide on + [Dockerizing a Node.js web app](https://nodejs.org/en/docs/guides/nodejs-docker-webapp/). + 1. Build a new image using `docker build`. ```bash