This repository contains a presentation and examples for building Docker images with Nix, presented at Nix Bern on June 26, 2025.
- Nix package manager with flakes enabled
- Docker (for running the built images)
-
Enter the development shell:
nix develop
-
Start the presentation:
presenterm -X -x presentation.md
Build a minimal container that runs the hello program:
# Build the image
nix-build hello.nix
# Load into Docker
docker load < result
# Run it
docker run hello-nix:latestThe spa/ directory contains a React SPA example that demonstrates:
- Building a Node.js application with Nix
- Creating a layered Docker image
- Serving static files with Caddy
- Alternative
container.nixfile to build a container to serve images using nginx
cd spa
# Build the Docker image
nix build .#docker
# Load into Docker
docker load < result
# Run the container
docker run -p 8080:80 spa-nix:latestYou can then visit http://localhost:8080 to see the running application.
Alternatively you can build the nginx based container image:
cd spa
# Build the Docker image
nix build -f container.nix
# Load into Docker
docker load < result
# Run the container
docker run -p 8080:80 spa-nix:latestYou can compare this image with the container image you can build using Dockerfile.nginx:
cd spa
docker build -t spa-docker -f Dockerfile.nginx .Use dive to explore the layer structure:
# Examine the layers
dive hello-nix:latest
dive spa-nix:latest- Reproducible: Same inputs always produce the same outputs
- Minimal: Only include what your application actually needs
- Cacheable: Efficient layer sharing across different images
- Transparent: Complete dependency tracking and SBOM generation
presentation.md- The main presentation slideshello.nix- Simple hello world container examplespa/- React SPA example with Dockerfile comparisonflake.nix- Development environment setuplinks.md- Useful resources and links
The flake provides all necessary tools for the presentation:
presenterm- For presenting the slidescrane- For examining container manifestsjq- For JSON processingqrencode- For generating QR codesdive- For exploring container layerssbomnix- For generating Software Bill of Materials