Persistent State in Containerlab Labs
Persistent State in Containerlab Labs
Thesis
Containerlab nodes are disposable until you bind-mount configs and state. This chapter focuses on what to persist. Containerlab was not executed here (no root / no installs); patterns cite containerlab.dev.
Mental model
deploy with binds → destroy → bind sources remain on host
| Persist | Typical bind |
|---|---|
| NOS config | ./configs/<node>:/etc/... |
| Scripts | ./scripts:/scripts:ro |
| Avoid | secrets world-readable; unreproducible captures |
Worked examples
name: persist-demo
topology:
nodes:
r1:
kind: linux
image: ghcr.io/nokia/srlinux
binds:
- ./configs/r1:/etc/opt/srlinux:ro
h1:
kind: linux
image: ghcr.io/srl-labs/network-multitool
binds:
- ./scripts:/scripts:ro
links:
- endpoints: ["r1:e1-1", "h1:eth1"]Use containerlab save when the kind supports dumping running config back to the bind source.
Trap
Weak modes on shared lab hosts. Prefer :ro for configs that should not be rewritten.
Boring rule
If you care about a file after destroy, it lives on the host via binds (or documented save tooling).
Try this
- Deploy/save/destroy/redeploy on a machine with Containerlab.
- Mirror with netlab (netlab.tools).
- Makefile target that diffs
./configsagainst golden files.
Sources
- https://containerlab.dev
- https://netlab.tools