What Does a containerlab YAML File Define?

Contents

Introduction

containerlab is a tool that declares a network topology (wiring diagram) in YAML and builds a virtual network exactly as described. https://containerlab.dev/

In this post, I look at what a containerlab configuration file like the one below defines.

name: test-lab

topology:
  nodes:
    host1:
      kind: linux
      image: XXXXXX
      binds: 
        - ./host1:/host1-folder
    host2:
      kind: linux
      image: XXXXXX
      binds: 
        - ./host2:/host2-folder
    switch:
      kind: linux
      image: XXXXXX
      binds: 
        - ./switch:/lab-folder

  links:
    - endpoints: ["host1:eth1", "switch:eth1"]
    - endpoints: ["host2:eth1", "switch:eth2"]

The structure of a containerlab YAML file

The sample above has the following structure.

name:
topology:
  nodes:
  links:
Section Role
name The name of the lab (configuration file)
topology.nodes Details of each node (name, type = kind, container image to use)
topology.links Connections between nodes (which interface of which node connects to which)

Let's dig into each one.

1. name: the lab's name

name: test-lab

The name declared here is used as a prefix for the names of the generated containers and networks.

Also, resources that containerlab generates automatically get clab- added, so you get names like

clab-test-lab-host1
clab-test-lab-host2
clab-test-lab-switch

That is, the naming is "clab- + lab name + node name".

2. nodes: details of each node

The node settings in the example at the top have the following structure.

nodes:
  host1:
    kind: linux
    image: XXXXXX
    binds: 
      - ./host1:/host1-folder
Key Meaning
host1 The node's name
kind What kind of network device to run it as
image The Docker container image the node uses (specify one from Docker Hub, GHCR, etc.)
binds Settings that mount files or directories on the host into the container
links:
  - endpoints: ["host1:eth1", "switch:eth1"]
  - endpoints: ["host2:eth1", "switch:eth2"]
  • endpoints = which interfaces of which nodes to connect to each other

Think of it as defining "virtual cables" between nodes. Behind the scenes, containerlab automatically creates veth pairs and connects them to each node.

The whole picture of the simple example

If you've followed this far, you should be able to picture what setup the YAML at the top describes.

name: test-lab

topology:
  nodes:
    host1:
      kind: linux
      image: XXXXXX
      binds: 
        - ./host1:/host1-folder
    host2:
      kind: linux
      image: XXXXXX
      binds: 
        - ./host2:/host2-folder
    switch:
      kind: linux
      image: XXXXXX
      binds: 
        - ./switch:/lab-folder

  links:
    - endpoints: ["host1:eth1", "switch:eth1"]
    - endpoints: ["host2:eth1", "switch:eth2"]

Here is the topology diagram generated by deploy:

Topology diagram: clab-test-lab-switch with eth1 linked to eth1 on clab-test-lab-host1, and eth2 linked to eth1 on clab-test-lab-host2

That covers the basics, and I think you now understand what role a containerlab YAML file plays 🙌

Translated from the Japanese original.

Thanks. I'll look into it.

Spotted a mistake?

Tell me what's wrong and I'll fix it. Only I see what you send.