Update build-images.md (#12843)

* Update build-images.md

Small typos in the documentation, which may lead to confusion.

* Inspiration from node.js docs

Added documentation for why we copy `package*.json` before copying the whole directory. Checkout: https://nodejs.org/en/docs/guides/nodejs-docker-webapp/#creating-a-dockerfile. 
The node.js docs has more optimized code too (using `npm ci` instead of `npm install`) which can be used here too.

* Fixed review provided and removed some weird whitespaces
This commit is contained in:
Aaryan Porwal 2021-07-30 18:26:05 +05:30 committed by GitHub
parent 33576a4efb
commit 6531e8ef21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 6 deletions

View File

@ -3,7 +3,7 @@ title: "Build your Node image"
keywords: containers, images, node.js, node, dockerfiles, node, coding, build, push, run
description: Learn how to build your first Docker image by writing a Dockerfile
redirect_from:
- /get-started/nodejs/build-images/
- /get-started/nodejs/build-images/
---
{% include_relative nav.html selected="1" %}
@ -40,12 +40,12 @@ Now, lets add some code to handle our REST requests. Well use a mock serve
Open this working directory in your IDE and add the following code into the `server.js` file.
```js
const ronin = require( 'ronin-server' )
const mocks = require( 'ronin-mocks' )
const ronin = require('ronin-server')
const mocks = require('ronin-mocks')
const server = ronin.server()
server.use( '/', mocks.server( server.Router(), false, true ) )
server.use('/', mocks.server(server.Router(), false, true))
server.start()
```
@ -145,7 +145,8 @@ Before we can run `npm install`, we need to get our `package.json` and `package-
COPY ["package.json", "package-lock.json*", "./"]
```
Once we have our `package.json` files inside the image, we can use the `RUN` command to execute the command npm install. This works exactly the same as if we were running npm install locally on our machine, but this time these Node modules will be installed into the `node_modules` directory inside our image.
Note that, rather than copying the entire working directory, we are only copying the package.json file. This allows us to take advantage of cached Docker layers.
Once we have our files inside the image, we can use the `RUN` command to execute the command npm install. This works exactly the same as if we were running npm install locally on our machine, but this time these Node modules will be installed into the `node_modules` directory inside our image.
```dockerfile
RUN npm install --production