Nix vs Docker for Development Environments
Docker reproduces a running Linux system. Nix reproduces the toolchain, package by package. Which one a team needs depends on what has to stay identical, and where it has to run.
By Build Stack Review · Last reviewed
The short answer
Use Docker when what you need to reproduce is a running Linux system: a database, a queue, a service your code talks to, or the exact image you ship to production. Use Nix when what you need to reproduce is the toolchain itself: compilers, language runtimes, CLIs and native libraries, pinned to exact versions and run natively on each developer's machine.
They are not exclusive. A common split is Nix for the toolchain and Docker Compose for the services, and Nix can also build the container images, so the dev shell and the image come from the same pinned definition.
Nix
A package manager and build system. Every package is installed into /nix/store under a path derived from a hash of all its build inputs, and nix develop (or nix-shell) opens a shell with exactly the pinned packages on your PATH.
Docker
A container engine. It builds images from a Dockerfile, layer by layer, and runs them as isolated processes on a Linux kernel: the host's on Linux, a Linux VM's on macOS and Windows.
Nix and Docker side by side
| Nix | Docker | |
|---|---|---|
| What it pins | Every package and its whole dependency graph, down to the C library, by the hash of its build inputs. | Whatever the Dockerfile's steps produce. A base image tag and apt-get install resolve to what is current at build time unless you pin digests and versions. |
| Rebuilding it later | The same nixpkgs revision (recorded in flake.lock, or a pinned tarball) resolves to the same store paths on another machine of the same platform. | Pulling the same image digest gives identical bits. Rebuilding the Dockerfile months later can give a different image. |
| Where your code runs | Natively on the host. On a Mac you get macOS binaries, with no VM in between. | Inside a Linux container. On macOS and Windows, Docker Desktop runs a Linux VM and bind-mounted source files cross a file-sharing layer. |
| Isolation | None for the dev shell: tools run as you, with your files and network. Package builds themselves run in a sandbox (on by default on Linux). | Process, filesystem and network isolation. The container sees only what you mount and the ports you publish. |
| macOS and Linux parity | Same package versions on both, but different binaries per platform, and some packages are Linux-only. | The same Linux image everywhere. Apple Silicon needs arm64 images or runs amd64 ones under emulation. |
| Databases and other services | Possible with packages and a process manager; devenv and Devbox add service definitions on top. | Its strength: one Compose file starts a database, cache and queue from published images. |
| Learning curve | The Nix language and its concepts (derivations, the store, flakes) take time. Wrappers such as Devbox, devenv and Flox hide most of it. | Dockerfiles and Compose files are widely known; most engineers can read and edit them. |
| Editor integration | direnv (with nix-direnv) loads the environment when you cd into the project; the editor sees native tools. | Dev Containers (devcontainer.json) open the project inside a container in VS Code, GitHub Codespaces and other supporting tools. |
| CI | Run the same nix develop command in CI; a binary cache saves rebuilding packages. | Run the job in the same image; most CI systems run container jobs natively. |
| Shipping to production | Can build OCI images directly with nixpkgs' dockerTools, from the same pinned inputs as the dev shell. | The image is the artifact most platforms (Kubernetes, ECS, Cloud Run) deploy. |
| Licence and cost | Nix and nixpkgs are open source. | Docker Engine is open source. Docker Desktop's terms for commercial use depend on the size of the company: check Docker's current pricing page. |
Which to choose
Choose Nix if
- Most of your engineers work on Macs and you want native speed, with no VM and no file-sync layer.
- Your drift is in the toolchain: Node, Python, Go or Rust versions, CLIs, native libraries like OpenSSL or libpq.
- You need to say exactly which version of every dependency a build used, for audits or provenance.
- You want the same environment definition to serve laptops, CI and production images.
Choose Docker if
- Your app depends on services (Postgres, Redis, Kafka) that you want running in one command.
- Production is a Linux container and you want local runs to match it closely.
- You want isolation: code, agents or scripts that should not see the rest of the machine.
- Your team already knows Dockerfiles and the cost of learning Nix isn't worth it yet.
What each one actually keeps identical
A Docker image is a snapshot. Once it is built and pushed, everyone who pulls the same digest gets the same bits. The Dockerfile that produced it is not a pin, though: FROM node:22-bookworm points at whatever that tag means today, and apt-get update && apt-get install fetches the archive's current versions. Rebuild in six months and you can get a different image from the same file, unless you pin the base image by digest and every package by version.
Nix pins the recipe instead of the result. A flake's flake.lock records the exact nixpkgs commit, and every package resolves to a store path derived from its inputs. Running nix develop next year, on another machine of the same platform, resolves to the same versions; anything not already on the machine is fetched from a binary cache or built from the same source.
FROM node:22-bookworm
RUN apt-get update && apt-get install -y postgresql-client
WORKDIR /app{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs = { self, nixpkgs }:
let pkgs = nixpkgs.legacyPackages.x86_64-linux;
in {
devShells.x86_64-linux.default = pkgs.mkShell {
packages = [ pkgs.nodejs_22 pkgs.postgresql ];
};
};
}The macOS question
Most teams write code on Macs and deploy to Linux, and this is where the two tools pull in opposite directions. Docker gives every developer the production OS, at the cost of a VM: memory set aside for it, and source files that cross a file-sharing layer on every read. Nix gives every developer the same versions of every tool, running natively, but on macOS those are macOS builds, so behaviour that depends on the OS can still differ from Linux.
Teams that pick Nix usually accept that trade and let CI, on Linux, catch what differs. Teams that pick Docker usually accept the VM. Neither tool removes the difference between a Mac and a Linux server; they just decide which side of it your code runs on.
Using them together
The two tools solve different halves of the problem, so many teams use both. The most common split: a Nix-based shell for the toolchain (the compilers, runtimes and CLIs every engineer runs directly), and Docker Compose for the databases and queues the app talks to.
Nix can also produce the container. nixpkgs' dockerTools builds OCI images from the same pinned packages as the dev shell, without a Dockerfile, so the toolchain in development and the runtime in production come from one lockfile. And where people need a container (GitHub Codespaces, for one), a dev container can install Nix and load the same environment inside it.
If Nix itself is the obstacle
The usual reason teams stay on Docker for development is not that Nix pins less; it is the Nix language. Several tools keep Nix's package store and pinning but replace the language with a simpler config: Devbox uses a devbox.json file, Flox an environment manifest, and devenv a smaller Nix module with services built in. Each still produces a lockfile, so the environment stays pinned; they differ in how much of Nix they let you reach when you need it.
Frequently asked questions
Is Nix a replacement for Docker?
For the toolchain on a developer's machine, often yes: it pins versions more precisely and runs without a VM. For running services, isolating processes, or shipping to a container platform, no. Nix can build the images, but you still run them on a container runtime.
Are Docker images reproducible?
A pushed image is fixed: the same digest is always the same image. Rebuilding one from its Dockerfile is not reproducible by default, because base image tags and package archives change. Pinning base images by digest and packages by version gets you closer; Docker's documentation covers reproducible builds with BuildKit and SOURCE_DATE_EPOCH.
Can Nix build Docker images?
Yes. nixpkgs' dockerTools (for example buildLayeredImage) builds OCI images from Nix packages without a Dockerfile, and the result loads into Docker or any registry like any other image.
Does Nix run on Windows?
Not natively. Windows developers run Nix inside WSL2, which gives them the Linux packages; Docker Desktop on Windows likewise runs Linux containers in a VM.
Do I need flakes?
No, but they are the most common way to pin nixpkgs today. Upstream Nix still marks flakes as experimental and needs them enabled in its configuration; some distributions of Nix, such as Determinate Nix, enable them by default. Check the Nix manual for the current status.
Sources
Tools change quickly: check versions, defaults and licence terms against each project’s own documentation before you decide.
- Nix reference manual
- nixpkgs manual: pkgs.dockerTools
- nix.dev: Building and running Docker images
- Nix: flakes stabilisation milestone
- Docker: Building best practices (pin base image versions)
- Docker: Reproducible builds with GitHub Actions
- Docker Desktop: Virtual Machine Manager
- Development Container Specification





