Add .dockerignore for node_modules & explanation
This commit is contained in:
parent
35dc319a76
commit
fc9025459a
@ -79,6 +79,21 @@ a change to the `package.json`. Make sense?
|
|||||||
CMD ["node", "/app/src/index.js"]
|
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`.
|
1. Build a new image using `docker build`.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
Loading…
Reference in New Issue
Block a user