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.
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
Packaging an application in docker
build /test logs/reports
Docker Builder pattern
Build in multiple stages
2 Docker files
1 – Build environment
2 – Run time environment
Doesn’t run everywhere
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
Multistage build exampleFROM node:latest AS storefront
COPY react-app .
RUN npm install
RUN npm run build
FROM maven:latest AS appserver
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
RUN adduser -Dh /home/gordon gordon
COPY --from=storefront /usr/src/atsea/app/react-app/build/ .
COPY --from=appserver /usr/src/atsea/target/AtSea-0.0.1-SNAPSHOT.jar .
ENTRYPOINT ["java", "-jar", "/app/AtSea-0.0.1-SNAPSHOT.jar"]
Create as many stages as needed