Skip to content

Commit fc90254

Browse files
committed
Add .dockerignore for node_modules & explanation
1 parent 35dc319 commit fc90254

File tree

1 file changed

+15
-0
lines changed
  • docs/tutorial/image-building-best-practices

1 file changed

+15
-0
lines changed

docs/tutorial/image-building-best-practices/index.md

+15
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ a change to the `package.json`. Make sense?
7979
CMD ["node", "/app/src/index.js"]
8080
```
8181

82+
1. Create a file named `.dockerignore` in the same folder as the Dockerfile with the following contents.
83+
84+
```ignore
85+
node_modules
86+
```
87+
88+
`.dockerignore` files are an easy way to selectively copy only image relevant files.
89+
You can read more about this
90+
[here](https://docs.docker.com/engine/reference/builder/#dockerignore-file).
91+
In this case, the `node_modules` folder should be omitted in the second `COPY` step because otherwise,
92+
it would possibly overwrite files which were created by the command in the `RUN` step.
93+
For further details on why this is recommended for Node.js applications and other best practices,
94+
have a look at their guide on
95+
[Dockerizing a Node.js web app](https://nodejs.org/en/docs/guides/nodejs-docker-webapp/).
96+
8297
1. Build a new image using `docker build`.
8398

8499
```bash

0 commit comments

Comments
 (0)