'Understanding Dockerfile syntax?
I am learning Docker and looking at this Dockerfile example for React application
FROM node:alpine
WORKDIR /app
COPY package.json ./
COPY package-lock.json ./
COPY ./ ./
RUN npm i
CMD ["npm", "run", "start"]
To me it's saying
- Grab image node:alpine from docker library
- create WORKDIR called /app
- copy the package.json file to the /app dir
- copy the lock file also to /app dir
- I don't understand what COPY ./ ./ is doing?
- command npm install
- then CMD npm run start
Am I interpreting this language correctly? Can anyone give me insight of what is actually going on?
Solution 1:[1]
Docker is an open-source containerization platform. Here we run our application in the container(which is managed by Docker Engine). Dockerfile contains all the commands. Also, you can say in Dockerfile that we write all the procedures to make a container runnable.
Coming back to your point...
Here COPY ./ ./ meaning is, COPY <source_path> <destination_path> and <source_path> is the path in your host machine and <destination_path> is path in your container machine
I will try to simplify the other contents in your Dockerfile...
FROM node:alpine: Pull imagenode:alpinefrom Docker Hub. Herenodeis the package name andalpineis the Linux distribution with very minimal and required packages.WORKDIR /app: (Work Directory) In container you're setting up yourWORKDIRas/appfolder.COPY package.json ./:COPYthepackage.json(host machine) file to./(current directory) in your containerAnd other
COPYwill also work in the same way.RUN npm i:RUNcommandnpm iin containerCMD ["npm", "run", "start"]:CMDcommand will executed(npm run start) when Docker Container will start.
For more detail please see Dockerfile Documentation.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dev |
