Description:

Docker Engine

Docker Build

Core concepts:

Overview:
  • Client: Buildx is the client and the user interface for running and managing builds.
  • Server: BuildKit is the server, or builder, that handles the build execution.
Dockerfile
Build context:
  • .

Building

Multi-stage
  • Use multi-stage builds
    • use multiple FROM statements in your Dockerfile.
    • Each FROM instruction can use a different base, and each of them begins a new stage of the build
    •   # syntax=docker/dockerfile:1
        FROM golang:1.24
        WORKDIR /src
        COPY <<EOF ./main.go
        package main
        
        import "fmt"
        
        func main() {
          fmt.Println("hello, world")
        }
        EOF
        RUN go build -o /bin/hello ./main.go
        
        FROM scratch
        COPY --from=0 /bin/hello /bin/hello
        CMD ["/bin/hello"]
  • Name build stages:
    • FROM golang:1.24 AS build
    • COPY --from=build /bin/hello /bin/hello
  • To stop at a specific build stage:

Docker Compose