The Problem Docker Solves
You write a Python script on your laptop. It works. You copy it to a jump server. It breaks because that server has a different Python version, or the Netmiko version is older, or the system is missing a library. This is the "it works on my machine" problem.
Docker fixes this by packaging the application and all its dependencies into a container. A container runs the same way on your laptop, the jump server, and in a CI pipeline , same Python, same libraries, same behavior.
Containers vs VMs: What Is Actually Different
A virtual machine runs a full operating system on top of a hypervisor. That means gigabytes of disk space, minutes to boot, and significant RAM overhead. For running one Python script, that's a lot.
A container shares the host's Linux kernel. It only packages the application and its dependencies , not a full OS. That makes containers start in under a second, use tens of megabytes instead of gigabytes, and run dozens of them on the same server where you might run a handful of VMs.
The tradeoff: containers are less isolated than VMs. A VM with a compromised application can't escape the hypervisor. A container with a compromised application shares the host kernel. For network automation tooling in a lab environment, this usually doesn't matter.
Core Docker Concepts
Image: a read-only blueprint. Contains the OS base layer, your app, and all dependencies. Stored in a registry (Docker Hub, your own registry).
Container: a running instance of an image. When it stops, it's gone (unless you use volumes for persistent data).
Dockerfile: the recipe that builds an image. A text file with instructions like "start from Python 3.11, install these packages, copy this file."
Registry: a storage system for images. Docker Hub is the public one. You pull images from it, push your own images to it.
Installing Docker
# Ubuntu/Debian
curl -fsSL https://get.docker.com | sudo sh
sudo usermod -aG docker $USER # run docker without sudo (re-login after) # Verify
docker run hello-world
On macOS or Windows, install Docker Desktop from docker.com. It includes everything you need.
Your First Useful Container
Pull and run a Python shell without installing Python locally:
docker run -it python:3.11 bash
-it gives you an interactive terminal. python:3.11 is the image (pulled from Docker Hub automatically). Once inside, you have a full Python 3.11 environment. Install packages with pip, run scripts , none of it touches your host system.
For network tooling:
docker run -it --rm networktocode/netutils bash
--rm removes the container when you exit. Good for one-off sessions.
Writing a Dockerfile for Your Automation Script
FROM python:3.11-slim WORKDIR /app COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt COPY . . CMD ["python", "run_automation.py"]
Build it: docker build -t my-automation .. Run it: docker run my-automation. The -slim variant of the Python image is about 50MB instead of 1GB , use it whenever you don't need the full Debian package set.
Your requirements.txt:
netmiko==4.3.0
nornir==3.4.0
nornir-netmiko==1.0.0
Pinning versions is important. Without them, a rebuild six months later might pull a different Netmiko version that breaks your scripts.
Volumes: Getting Files In and Out
Containers are ephemeral , anything written inside is lost when the container stops. Mount a directory from your host to persist data:
docker run -v /home/user/configs:/app/configs my-automation
Now /app/configs inside the container is the same as /home/user/configs on your host. Scripts can read device inventory files or write config backups, and they persist after the container exits.
Docker Compose for Multi-Container Labs
Some lab setups need multiple containers working together , your automation script plus a mock API server, or multiple containers representing different parts of a pipeline. Docker Compose handles this with a YAML file.
services: automation: build: . volumes: - ./configs:/app/configs depends_on: - mock-api mock-api: image: mockserver/mockserver ports: - "1080:1080"
Run everything: docker compose up. Stop it: docker compose down.
When Containers Matter for Networking
A few situations where Docker is specifically useful for network engineers:
CI/CD pipelines: run your automation tests in a consistent Docker container. No "it worked on my laptop" failures in the pipeline.
Containerlab: a tool that runs network OS containers (cEOS, cRPD, SR Linux) for lab topologies. Docker is the prerequisite.
Distributing tools: share your automation scripts as a Docker image. Anyone can pull it and run it without dealing with Python versions or dependencies.
Batfish: the network analysis tool runs as a Docker container.
docker run batfish/allinoneis the entire install process.
Watch the video
This topic has a full video on YouTube.
Comments (0)
Please sign in to comment.