DevOps Classroom notes 17/Sep/2026

Docker Multi-stage

  • A multi-stage build have a single dockerfile with more then one from instruction.
  • last from will be main image
  • alas name for stages
  • multiple stages will suppourted
  • --copy-files to main image.
  • it will be reduce my docker image size

what problem its sloved

  1. one fat image:
  • it will contains all packages and build tools and logs , testcases …etc
  • everything in single image
  1. Build pattern (multiple docker files)
  • Dockerfile.build : install pre-requests and build code

  • cp required files to local or remote

  • copy above files to new docker image (Dockerfile)

  • java ==> amazoncorretto (os amazon linux2)

  • alpine ==> linux kernerl light weight os

Ex:

git clone https://github.com/spring-projects/spring-petclinic.git

FROM ubuntu AS source-code 

WORKDIR app

RUN git clone https://github.com/spring-projects/spring-petclinic.git

FROM maven:3.8.3-openjdk-17 AS builder

COPY  --from=source-code app/spring-petclinic spring-petclinic

WORKDIR spring-petclinic

RUN mvn clean package -DskipTests

FROM openjdk:17.0.2-jdk AS prod

ENV JAVA_HOME=/usr/jvm/openjdk-17-jdk/bin/

WORKDIR app

COPY --from=builder spring-petclinic/target/*.jar app.jar

COPY --from=source-code app/spring-petclinic/pom.xml pom.xml

CMD ["java", "-jar", "app.jar"]

Task:

  1. create multistage build for nop
  2. refer here manuall steps
  3. refer_source_code

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Animated Social Media Icons by Acurax Responsive Web Designing Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube