DevSecOps for BBK
  • Introduction
  • Getting Started
    • Virtual Training Practices
    • Training Plan
    • Tools and Configuration
    • Troubleshooting
  • Docker Fundamentals
    • Docker Setup
    • Docker First Container
    • Docker Network Basics
    • Docker Network Exercise
    • Docker Volume Basics
    • Docker Storage
  • Dockerfile Fundamentals
    • Dockerfile Instructions
    • Dockerfile Environment Variables
    • Dockerfile Build Arguments
    • Non-privileged Containers
    • Dockerfile Order of Execution
    • Dockerfile Volume
    • Entrypoint Command
    • Multiple Stage Build
  • Container Management
    • Containers Start Automatically
  • Docker Security
    • Seccomp Profile
  • Docker Compose
    • Docker Compose Install
    • Docker Compose Commands
    • Docker Compose File
    • Docker Compose Volumes and Network
  • K8s Cluster Setup
    • Minikube Installation
    • Calico Networking
    • K8s Walkthrough
    • K8s Cheat Sheet
  • Understand K8s
    • Pod Connectivity
    • Deployments
    • Service Cluster IP
    • Service NodePort
    • ClusterIP Exercise
    • NodePort Exercise
    • Service LoadBalancer
    • Configmap
    • Secrets
  • Application Lifecycle Management
    • Rolling Updates and Rollback
    • Multi Container Pod
  • K8s Storage
    • Persistent Volume
    • Persistent Volume Claim
    • PVC in POD
  • Istio
    • AKS Setup
    • Kubectl Setup in Windows
    • Istio Setup Manual
    • Istio Demo App
    • Istio Observability
  • Terraform
    • Terraform Setup
    • Terraform Demo
    • Azure Terraform Setup
  • Terraform AWS
    • Terraform AWS Setup
    • Terraform AWS Demo S3
  • Refrences
    • Docker Static Site
    • Docker First Image
Powered by GitBook
On this page
  1. Dockerfile Fundamentals

Multiple Stage Build

In this lesson, we will learn how to build smaller images using multi-stage builds.

By default, the stages are not named Stages are numbered with integers Starting with 0 for the first FROM instruction Name the stage by adding as to the FROM instruction Reference the stage name in the COPY instruction

Step 1: Set up your environment:

cd docker_images
mkdir multi-stage-builds
cd multi-stage-builds
git clone https://github.com/nishanthkumarpathi/content-weather-app.git src

Step 2: Create the Dockerfile:

vi Dockerfile

Step 3: Create an image for the weather-app using multi-stage build

Dockerfile contents:

FROM node AS build
RUN mkdir -p /var/node/
ADD src/ /var/node/
WORKDIR /var/node
RUN npm install

FROM node:alpine
ARG VERSION=V1.1
LABEL org.label-schema.version=$VERSION
ENV NODE_ENV="production"
COPY --from=build /var/node /var/node
WORKDIR /var/node
EXPOSE 3000
ENTRYPOINT ["./bin/www"]

Step 4: Create an image for the weather-app using multi-stage build

docker image build -t nishanthkp/weather-app:multi-stage-build --rm --build-arg VERSION=1.5 .

Step 5: List images to see the size difference:

docker image ls

Step 6: Create the weather-app container:

docker container run -d --name multi-stage-build -p 8087:3000 nishanthkp/weather-app:multi-stage-build
PreviousEntrypoint CommandNextContainer Management

Last updated 2 years ago