Dockerfile
Agenda
● What is Dockerfile?
● Docker Build Context
● Dockerfile Format
● Dockerfile Instructions
● Demo
What is Dockerfile?
● It is simple Text file with a set of command or Instruction to perform the
actions on the base image to create a new docker image
● Docker can build images automatically by reading the instruction from
Dockerfile
● Using docker build users can create an automated build that execute several
command line instruction in succession
Docker Build Context
The Docker Build command build an image from Dockerfile and context
The Build context is the set of files at specified location Path or URL. The Path is a
directory on your local filesystem.
Maintain .dockerignore file same as .gitignore to exclude the context in build
Dockerfile Format
Dockerfile must begin with a FROM instruction
From may only be preceded by one or more ARG instruction, which declare
arguments that are used in FROM line in the file
Dockerfile format is
# Comment
INSTRUCTION arguments
Dockerfile Instruction: FROM
Dockerfile Instruction: LABEL
Dockerfile Instruction: EXPOSE
Dockerfile Instruction: WORKDIR
Dockerfile Instruction: ADD
Dockerfile Instruction: COPY
Dockerfile Instruction: USER
Dockerfile Instruction: ENV
Dockerfile Instruction: RUN
Dockerfile Instruction: ENTRYPOINT
Dockerfile Instruction CMD
Sample Dockerfile
# Step 1: Setup Node Container
FROM node:18 AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . ./
RUN npm run build
# Step 2: Serve the application using Nginx
FROM nginx:alpine
COPY --from=build /app/build /usr/share/nginx/html
EXPOSE 80
Create Image using Dockerfile and Run the container
# cd $Project_folder
# docker build -t myreact-app .
[-t = Create tag on image]
[myreact-app = Tagname]
# docker run -td --name node -p 80:80 myreact-app:latest
Thank You

Presentation on the Dockerfile by Techserver