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