Explain the use of the `COPY` command in the NodeJS example (#13711)

* Explain the use of the COPY command in nodejs example

* Format updates

Co-authored-by: Usha Mandya <47779042+usha-mandya@users.noreply.github.com>
This commit is contained in:
Dan Bamikiya 2021-11-19 13:18:37 +01:00 committed by GitHub
parent 0d0932d1b7
commit cc5d5db7c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -130,7 +130,14 @@ WORKDIR /app
Usually the very first thing you do once youve downloaded a project written in Node.js is to install npm packages. This ensures that your application has all its dependencies installed into the `node_modules` directory where the Node runtime will be able to find them.
Before we can run `npm install`, we need to get our `package.json` and `package-lock.json` files into our images. We use the `COPY` command to do this. The `COPY` command takes two parameters. The first parameter tells Docker what file(s) you would like to copy into the image. The second parameter tells Docker where you want that file(s) to be copied to. Well copy the `package.json` and `package-lock.json` file into our working directory `/app`.
Before we can run `npm install`, we need to get our `package.json` and `package-lock.json` files into our images. We use the `COPY` command to do this. The `COPY` command takes two parameters: `src` and `dest`. The first parameter `src` tells Docker what file(s) you would like to copy into the image. The second parameter `dest` tells Docker where you want that file(s) to be copied to. For example:
```dockerfile
COPY ["<src>", "<dest>"]
```
You can specify multiple `src` resources seperated by a comma. For example, `COPY ["<src1>", "<src2>",..., "<dest>"]`.
Well copy the `package.json` and the `package-lock.json` file into our working directory `/app`.
```dockerfile
COPY ["package.json", "package-lock.json*", "./"]