Merge pull request #47 from dmahnkopf/master

Add .dockerignore for node_modules & explanation
This commit is contained in:
Stefan Scherer 2020-06-26 09:12:17 +02:00 committed by GitHub
commit ef2a395b78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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