Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Docker multi stage builds


Published on

Docker multi stage builds

Published in: Engineering
  • Be the first to comment

  • Be the first to like this

Docker multi stage builds

  1. 1. Docker Multi-stage builds By Rathneesh TM (HPE) Bangalore Docker Meetup #33
  2. 2. Docker build Builds Docker images from a Dockerfile and a “context”. A build’s context is the files located in the specified PATH or URL. The build process can refer to any of the files in the context. Each directive in Dockerfile creates a layer. Each Dockerfile generates on image.
  3. 3. Docker image build best practices Avoid installing unnecessary packages Each container should have only one concern Minimize the number of layers Minimize the size of the image
  4. 4. Packaging an application in docker image application compiler test code build /test logs/reports application
  5. 5. Docker Builder pattern Build in multiple stages 2 Docker files 1 – Build environment 2 – Run time environment Work flow Doesn’t run everywhere
  6. 6. Docker multi stage builds Available from Docker 17.05. Extended FROM and COPY directives. Supports Multiple FROM directives. Each FROM statement is start of a new context. COPY from any previous stage to the current context. The last FROM directive creates the final image. The FROM syntax also supports AS keyword
  7. 7. Multistage build exampleFROM node:latest AS storefront WORKDIR /usr/src/atsea/app/react-app COPY react-app . RUN npm install RUN npm run build FROM maven:latest AS appserver WORKDIR /usr/src/atsea COPY pom.xml . RUN mvn -B -f pom.xml -s /usr/share/maven/ref/settings-docker.xml dependency:resolve COPY . . RUN mvn -B -s /usr/share/maven/ref/settings-docker.xml package -DskipTests FROM java:8-jdk-alpine RUN adduser -Dh /home/gordon gordon WORKDIR /static COPY --from=storefront /usr/src/atsea/app/react-app/build/ . WORKDIR /app COPY --from=appserver /usr/src/atsea/target/AtSea-0.0.1-SNAPSHOT.jar . ENTRYPOINT ["java", "-jar", "/app/AtSea-0.0.1-SNAPSHOT.jar"] CMD [""]
  8. 8. Simplified One Dockerfile One syntax(Dockerfile) one build Create as many stages as needed
  9. 9. References