| marp | true |
|---|
base + code + dev tools + compiler + tests + build + ...
- Adding more layers increase the image size
- Large images not only take time to build but also push and pull form a registry
- Smaller imges reduce build times and time to deploy
- Smaller images are more secure because the attacker surface is smaller
Multi-stage builds allow us to have multiple stages.
-
Multi-stage builds: Separate stages in a single Dockerfile
-
Build pattern: Build with an CI tool, then copy artifacts over.
FROM node:12.13.0-alpine as build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx
EXPOSE 3000
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/build /usr/share/nginx/html--> 06-examples-compose/dotnet-minimal-web-api
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /app
# Copy everything
COPY . .
# Restore as distinct layers
RUN dotnet restore
# Build and publish a release
RUN dotnet publish -c Release -o published-app
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0 as runtime
WORKDIR /app
# Copy only the artifact from the build stage
COPY --from=build /app/published-app .
ENTRYPOINT ["dotnet", "NotesMinimalAPI.dll"]



