ContainerLab 〡 Tutorials

ContainerLab for Network Automation Labs – Part 1

Milan Zapletal
December 21, 2025

Table Of Contents

Modern network automation requires safe, isolated environments for testing configurations and validating automation scripts. Google Cloud Platform combined with ContainerLab for Network Automation Labs provides an excellent foundation for creating these lab environments. In this post, we’ll walk through deploying a Google Cloud VM with nested virtualization support and installing ContainerLab.

Why Google Cloud for Network Labs?

Google Cloud offers several advantages for network automation testing:

  • Nested Virtualization Support: Run virtual network devices inside cloud VMs
  • Scalable Resources: Adjust compute power based on lab complexity
  • Cost-Effective: Pay only for what you use during testing
  • Geographic Flexibility: Deploy labs closer to your team or customers

Additionally, my personal opinion is that GCP is very intuitive, has great documentation, CLI tools and very responsive and easy to navigate UI.

Prerequisites

Before starting, ensure you have:

  • Google Cloud account with billing enabled
  • gcloud CLI tool installed and configured
  • Basic familiarity with Linux command line
  • Understanding of network automation concepts

Step 1: Enable Required APIs

First, enable the necessary Google Cloud APIs:

Bash
gcloud services enable compute.googleapis.com
gcloud services enable cloudresourcemanager.googleapis.com

Step 2: Create VM with Nested Virtualization (Modern Approach)

Google Cloud now provides a simpler method to enable nested virtualization without requiring custom images. Previously, you needed to create a custom image with the enable-vmx license, but Google now recommends using the --enable-nested-virtualization flag directly.

Why Nested Virtualization?

Nested virtualization allows us to run virtual network devices (like router and switch containers) inside our cloud VM. This is essential for ContainerLab, which relies on containerized network operating systems that need access to virtualization features.

Create your VM instance with nested virtualization enabled:

ShellScript
gcloud compute instances create containerlab-server \
    --zone=us-central1-a \
    --machine-type=n1-standard-4 \
    --network-tier=PREMIUM \
    --maintenance-policy=MIGRATE \
    --can-ip-forward \
    --provisioning-model=STANDARD \
    --enable-nested-virtualization \
    --min-cpu-platform="Intel Haswell" \
    --image-family=ubuntu-2204-lts \
    --image-project=ubuntu-os-cloud \
    --boot-disk-size=100GB \
    --boot-disk-type=pd-standard \
    --boot-disk-device-name=containerlab-server \
    --tags=containerlab-server

Key Parameters Explained:

  • --enable-nested-virtualization: Enables running VMs inside the VM
  • --min-cpu-platform="Intel Haswell": Required for nested virtualization
  • --machine-type=n1-standard-4: 4 vCPUs and 15GB RAM (adjust based on your needs)
  • --boot-disk-size=100GB: Sufficient space for containers and network topologies
  • --can-ip-forward: Enable IP Forwarding to use VPC routes

Step 3: Connect to Your VM

Connect to your newly created instance:

ShellScript
gcloud compute ssh containerlab-server --zone=us-central1-a

Step 4: Verify Nested Virtualization

Once connected, verify that nested virtualization is enabled:

ShellScript
# Check for VMX support
grep -c vmx /proc/cpuinfo

# Verify KVM support
sudo apt update
sudo apt install -y cpu-checker
kvm-ok

You should see output confirming VMX support and KVM acceleration availability.

Step 5: Install Docker

ContainerLab requires Docker to run network device containers:

Bash
# Install Docker using the official script
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

# Add your user to the docker group
sudo usermod -aG docker $USER

# Start and enable Docker service
sudo systemctl start docker
sudo systemctl enable docker

# Log out and back in for group changes to take effect
exit

Reconnect to your VM and verify Docker installation:

ShellScript
gcloud compute ssh containerlab-server --zone=us-central1-a
docker --version
docker run hello-world

Step 6: Install ContainerLab

Install the latest version of ContainerLab:

ShellScript
# Download and install ContainerLab
curl -sL https://containerlab.dev/setup | sudo -E bash -s "all"

# Verify installation
containerlab version

# Check available container images for network devices
containerlab inspect --all

ContainerLab supports various network operating systems including:

  • Arista cEOS: Arista’s containerized EOS
  • Nokia SR Linux: Nokia’s container-native NOS
  • Cisco XRd: Cisco’s containerized IOS XR
  • Juniper cRPD: Juniper’s containerized routing protocol daemon
  • FRRouting: Open-source routing suite

Step 7: Test ContainerLab for network automation lab

ContainerLab with 2 linux alpine units running on Google Cloud VM

Create a simple test topology to verify everything works:

Bash
# Create a test directory
mkdir ~/clab-test
cd ~/clab-test

# Create a basic topology file
cat > simple-test.yml << 'EOF'
name: simple-test
topology:
  nodes:
    alpine1:
      kind: linux
      image: alpine:latest
      exec:
        - ip addr add 192.168.1.1/24 dev eth1
    alpine2:
      kind: linux
      image: alpine:latest
      exec:
        - ip addr add 192.168.1.2/24 dev eth1
  links:
    - endpoints: ["alpine1:eth1", "alpine2:eth1"]
EOF

# Deploy the topology
sudo containerlab deploy -t simple-test.yml

# Verify deployment
sudo containerlab inspect -t simple-test.yml

# Test connectivity between containers
sudo docker exec clab-simple-test-alpine1 ping -c 3 172.20.20.3

# Access container shell
sudo docker exec -it clab-simple-test-alpine1 sh

# Clean up when done
sudo containerlab destroy -t simple-test.yml

This test creates two Alpine Linux containers connected via a virtual link and verifies they can communicate.

Example output of the inspect command after deployment:

ShellScript
$ sudo containerlab inspect -t simple-test.yml
16:03:28 INFO Parsing & checking topology file=simple-test.yml
╭──────────────────────────┬───────────────┬─────────┬───────────────────╮
           Name              Kind/Image    State     IPv4/6 Address  
├──────────────────────────┼───────────────┼─────────┼───────────────────┤
 clab-simple-test-alpine1  linux          running  172.20.20.2       
                           alpine:latest           3fff:172:20:20::2 
├──────────────────────────┼───────────────┼─────────┼───────────────────┤
 clab-simple-test-alpine2  linux          running  172.20.20.3       
                           alpine:latest           3fff:172:20:20::3 
╰──────────────────────────┴───────────────┴─────────┴───────────────────╯

Testing connectivity and shell access:

ShellScript
$ sudo docker exec clab-simple-test-alpine1 ping -c 3 172.20.20.3
PING 172.20.20.3 (172.20.20.3): 56 data bytes
64 bytes from 172.20.20.3: seq=0 ttl=64 time=0.133 ms
64 bytes from 172.20.20.3: seq=1 ttl=64 time=0.086 ms
64 bytes from 172.20.20.3: seq=2 ttl=64 time=0.075 ms
ShellScript
$ sudo docker exec -it clab-simple-test-alpine1 sh
/ # route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         172.20.20.1     0.0.0.0         UG    0      0        0 eth0
172.20.20.0     *               255.255.255.0   U     0      0        0 eth0
192.168.1.0     *               255.255.255.0   U     0      0        0 eth1
/ # exit

Understanding the Legacy VMX License Approach

Historical Context: You may encounter older tutorials that create custom images with VMX licenses. Here’s why this was necessary and why it’s no longer recommended:

ShellScript
# Legacy method (NOT recommended for new deployments)
gcloud compute images create nested-ubuntu-jammy \
    --source-image-family=ubuntu-2204-lts \
    --source-image-project=ubuntu-os-cloud \
    --licenses https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx

Why the VMX license was needed: Google Cloud’s hypervisor doesn’t expose Intel VT-x virtualization instructions to VMs by default. The enable-vmx license instructed the hypervisor to enable these hardware virtualization features, allowing nested VMs to run.

Modern approach advantage: The --enable-nested-virtualization flag achieves the same result without requiring custom image creation, simplifying deployment and maintenance.

For optimal performance in your network labs:

  1. Choose the Right Machine Type: Start with n1-standard-4, scale up for complex topologies
  2. Use SSD Persistent Disks: Better I/O performance for container operations
  3. Enable IP Forwarding: Essential for routing labs
  4. Monitor Resource Usage: Use htop and docker stats to monitor resource consumption

Troubleshooting Common Issues

Issue: “KVM acceleration cannot be used”
Solution: Ensure you selected Intel Haswell or newer CPU platform and enabled nested virtualization

Issue: Docker permission denied
Solution: Ensure user is added to docker group and you’ve logged out/in

Issue: ContainerLab deployment fails
Solution: Check available disk space and ensure Docker daemon is running

Security Considerations

When running network labs in the cloud:

  • Limit External Access: Only open necessary ports
  • Use Strong SSH Keys: Disable password authentication
  • Regular Updates: Keep the OS and container images updated
  • Network Isolation: Consider using VPC networks for isolation

With your Google Cloud VM and ContainerLab properly configured, you’re ready to:

  • Deploy complex network topologies
  • Test network automation scripts
  • Validate configuration changes safely
  • Practice network troubleshooting scenarios

In our next post, we’ll explore deploying a NetOps server environment and enabling advanced routing features for realistic network automation testing.

Cost Management

To keep costs under control:

  • Stop or Suspend instances when not in use (storage costs continue)
  • Use preemptible instances for non-critical testing
  • Set up billing alerts to monitor spending
  • Clean up unused resources regularly

This foundation provides a robust platform for network automation development and testing. The combination of Google Cloud’s infrastructure and ContainerLab’s networking capabilities creates an ideal environment for modern network operations teams.

Related Posts:


At Netodata, we specialize in helping organizations build robust network automation practices. Contact us to learn how we can help you implement similar solutions in your environment.

NETWORK AUTOMATION INSIGHTS
Stay informed about the latest in network automation:
Technical deep dives - Implementation guides -
Industry best practices
Netodata official logo featuring a stylized green geometric icon and the brand name "NETODATA" in white and green typography on a transparent background.
From initial consulting to seamless implementation, we manage your network automation journey every step of the way. Our comprehensive suite of professional services caters to diverse enterprises, ranging from startups to established players.
Contact
1-234-1234
info@netodata.io
Address
Nové sady 988/2
602 00, Brno
Czech Republic
ICO: 23213035
GET IN TOUCH
Address
Netodata Labs, s.r.o. © 2026 All Rights Reserved
Nautobot icon

Nautobot

The central Source of Truth for network infrastructure data. Nautobot serves as:
Authoritative inventory database
IP address components tracking
Configuration template repository
Automation platform

Nornir

A Python automation framework specifically designed for network automation. Nornir provides:
High-performance concurrent task execution
Deep Python integration
Flexible inventory management
Fine-grained control over network operations
CI/CD

Orchestration & CD/CI

We integrate industry-standard orchestration tools to ensure reliable automation delivery:
Git-based version control
Automated pipelines
Controlled deployment workflows
Continuous integration practices

Ansible

An industry-standard automation platform that excels at network configuration management. We utilize Ansible for:
Network device configuration deployment
State validation and compliance checking
Integration with custom Python modules
Standardized workflow automation

Netbox

The central Source of Truth for network infrastructure data. NetBox serves as:
Authoritative inventory database
IP address components tracking
Configuration template repository
REST API provider for automation workflows

Python

The foundation of our automation framework, Python enables us to create modular, maintainable, and efficient network automation solutions. We leverage Python's extensive standard library and carefully selected packages to build:
Reusable automation components
Custom network management tools
API integrations
Data processing pipelines