Docker - Dockerfile
What is Dockerfile?
A Dockerfile is a text document that contains commands that are used to assemble an
image. We can use any command that call on thecommand line. Docker buildsimagesautomatically by reading theinstructionsfrom theDockerfile.The docker build command is used to build an
imagefrom theDockerfile. You can use the-f flagwithdocker buildto point to aDockerfileanywhere in your file system.
$ docker build -f /path/to/a/Dockerfile .
Dockerfile Instructions
The
instructionsare not case-sensitive but you must follow conventions which recommend to use uppercase.Docker runs
instructionsofDockerfilein top to bottom order. The firstinstructionmust beFROMin order to specify theBase Image.A statement begin with
#treated as acomment. You can useRUN,CMD,FROM,EXPOSE,ENVetc instructions in yourDockerfile.
FROM
- This instruction is used to set the 
Base Imagefor the subsequent instructions. A validDockerfilemust have FROM as its firstinstruction. 
FROM node:latest
LABEL
- We can add labels to an 
imageto organize images of our project. We need to useLABELinstruction to set label for theimage. 
LABEL maintainer = "CUBETIQ"
WORKDIR
- The 
WORKDIRis used to set the working directory for anyRUN,CMDandCOPYinstruction that follows it in theDockerfile. If work directory does not exist, it will be created by default. We can useWORKDIRmultiple times in aDockerfile. 
WORKDIR /app
COPY
- This instruction is used to copy new files or directories from 
sourceto the filesystem of the container at thedestination. 
COPY package*.json ./
RUN
- This instruction is used to execute any command of the 
current image. 
RUN npm install
CMD
- This is used to execute 
applicationby theimage. There can be only oneCMDin aDockerfile. If we use more than oneCMD, only last one will execute. 
CMD ["node", "app.js"]