Getting Started with Containerlab
What is Containerlab?
Containerlab is an open-source tool that simplifies the deployment of container-based networking labs. It uses Docker and containerized network operating systems (NOS) like FRR, Nokia SR Linux, Arista cEOS, Cisco NX-OS, and SONiC to create realistic network environments.
Why Use Containerlab?
Lightweight – Uses containers instead of full VMs
Faster Deployment – Start up a lab in seconds
Multi-Vendor Support – Cisco, Arista, Nokia, Juniper, and more
Reproducibility – YAML-based configuration for easy sharing
Integration with Automation – Works well with Ansible, Netconf, and gRPC
Installing Containerlab
Containerlab requires Docker and sudo/root privileges to run.
Step 1: Install Docker
Containerlab runs on top of Docker, so ensure you have it installed:
1
sudo apt update && sudo apt install -y docker.io
Verify Docker is running:
1
docker --version
Step 2: Install Containerlab
The easiest way to install Containerlab is via the official script:
1
bash -c "$(curl -sL https://get.containerlab.dev)"
Alternatively, install manually using deb or rpm packages:
1
2
curl -sL https://github.com/srl-labs/containerlab/releases/latest/download/containerlab-linux-amd64 -o /usr/local/bin/containerlab
chmod +x /usr/local/bin/containerlab
Step 3: Verify Installation
After installation, check if Containerlab is working:
1
containerlab version
Understanding Containerlab Topology Files
Containerlab uses a YAML-based topology definition file. This file defines nodes (devices), links, and management settings.
Basic Structure of a Containerlab Topology File
1
2
3
4
5
6
7
8
9
10
11
12
13
14
name: my-first-lab
topology:
nodes:
router1:
kind: vr-ros
image: vrnetlab/vr-routeros:latest
router2:
kind: vr-ros
image: vrnetlab/vr-routeros:latest
links:
- endpoints: ["router1:eth1", "router2:eth1"]
Key Sections:
- name – Name of the lab
- topology – Defines all devices and links
- nodes – Lists the devices (e.g., routers, switches)
- kind – Specifies the device type (e.g.,
vr-rosfor RouterOS,ceosfor Arista EOS) - image – The Docker image used
- links – Defines connections between devices
Deploying Your First Lab
Now, let’s deploy and manage a simple lab with two routers.
Step 1: Define the Topology
Create a new directory for your lab and navigate into it:
1
mkdir ~/containerlab-labs && cd ~/containerlab-labs
Create a new YAML file (mylab.clab.yml) and add the following:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
name: simple-lab
topology:
nodes:
r1:
kind: vr-ros
image: vrnetlab/vr-routeros:latest
r2:
kind: vr-ros
image: vrnetlab/vr-routeros:latest
links:
- endpoints: ["r1:eth1", "r2:eth1"]
Step 2: Deploy the Lab
Run the following command to deploy the lab:
1
sudo containerlab deploy -t mylab.clab.yml
Once deployed, list running labs:
1
containerlab inspect
To see the running Docker containers:
1
docker ps
Logging into Nodes
Once the lab is deployed, you can access the network devices using different methods.
Method 1: Using docker exec
Each node runs as a Docker container. To access a node’s shell:
1
docker exec -it r1 vtysh
or for a Bash shell:
1
docker exec -it r1 /bin/bash
For routers running Cisco’s IOS-XE or Arista EOS:
1
docker exec -it r1 Cli
Method 2: Using containerlab inspect
Get the management IP of a node:
1
containerlab inspect -t mylab.clab.yml
Find the IP under mgmt_ipv4 and SSH into it:
1
ssh admin@<MGMT-IP>
Example:
1
ssh admin@172.20.20.2
Method 3: Directly Connecting via Terminal
For NOS images like Arista cEOS, Cisco NX-OS, or Nokia SR Linux, they expose a default SSH port. You can SSH using:
1
ssh -p 22 admin@$(docker inspect -f '' r1)
For containers exposing console ports via telnet, check with:
1
docker ps | grep r1
Then connect using:
1
telnet 127.0.0.1 <PORT>
Stopping and Deleting Labs
Once you’re done, clean up the environment with:
1
sudo containerlab destroy -t mylab.clab.yml
This will stop and remove the containers while keeping the YAML file intact.