Skip to content

Commit

Permalink
Merge pull request docker#47 from dmahnkopf/master
Browse files Browse the repository at this point in the history
Add .dockerignore for node_modules & explanation
  • Loading branch information
StefanScherer authored Jun 26, 2020
2 parents e1b7106 + fc90254 commit ef2a395
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/tutorial/image-building-best-practices/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ef2a395

Please sign in to comment.