DevOps Classroom notes 10/Oct/2024

Optimizing Images

Simple Fastapi application

  • Refer Here for steps
  • Required:
    • python 3.13
  • Steps:
    • copy code
    • install dependencies
    • Expose port
  • How to run Appl uvicorn main:app --host 0.0.0.0 --port 8000 --reload
  • Refer Here for first version of Dockerfile
  • Refer Here for change to slim version
  • Refer Here for changes to use a non root user
  • When we tried as a non root user, we are getting permission issues
  • Refer Here for the possible solution where we build dependencies in one stage and copy them into other with permissions to the user

Simple Spring boot (Java) application

  • Existing Dockerfile
FROM eclipse-temurin:17-jre
ADD https://khajareferenceapps.s3.ap-south-1.amazonaws.com/spring-petclinic-3.2.0-SNAPSHOT.jar /spc.jar
EXPOSE 8080
CMD ["java", "-jar", "/spc.jar"]
  • We are building the jar file seperately and using them in Docker Image building process.
  • The idea is to build the jar and use the jar as part of Docker Image building itself

Multi stage Dockerfiles

  • This is inspired from a builder pattern
  • Refer Here for multistage docker for spring petclinic
FROM maven:3.9-eclipse-temurin-17 AS builder
# build the java code
COPY . /spc
WORKDIR /spc
RUN mvn package
# this will create a spring petclinic jar file


FROM eclipse-temurin:17-jre AS runner
COPY --from=builder --chown=ubuntu /spc/target/spring-petclinic-3.3.0-SNAPSHOT.jar /app/spring-petclinic.jar
USER ubuntu
WORKDIR /app
EXPOSE 8080
CMD ["java", "-jar", "spring-petclinic.jar"]

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

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