Description:

Docker Engine

Install

Storage

.
  • Container layer basics
  • Storage mount options
    • volume mounts
    • bind mounts
    • tmpfs mounts
    • named pipes
Volume
Bind mounts
tmpfs mounts
Storage drivers
  • .
    • Storage driver vs Docker Volume
      • storage driver:
        • Docker uses storage drivers to store image layers, and to store data in the writable layer of a container
        • Container’s writable layer doesnt persist, only for ephemeral data
        • write speeds are lower than native file system performance
      • Docker volumns:
        • for write-intensive data
        • persist after container is deleted
        • data must be shared between containers
    • Image and layers:
      • Each layer represents an instruction in the image’s Dockerfile. Each layer except the very last one is read-only.
        • FROM creating a layer for base image
        • COPY adds some files to system disk
        • RUN executes command, result to write to system disk
        • LABEL only modifies the image’s metadata
      • Each layer is only a set of different from the layer before it
      • The layers are stacked on top of each other. When you create a new container, you add a new writable layer on top of the underlying layers
      • A storage driver handles the details about the way these layers interact with each other.
    • Container and layers:

Networking

Container

CLI

Docker Daemon

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:

Cache:

  • How the build cache works:
    • Any instruction that modifies the system disk will create a Docker image layer:
      • FROM, RUN, COPY, ADD
      • do not create layer: CMD, ENTRYPOINT, WORKDIR, EXPOSE, ENV, LABEL, USER, VOLUME, STOPSIGNAL, ARG
    • When ever an instruction changes, that layer and any layer built after it will be rebuilt
Building cache invalidation

Docker Compose