Skip to content

graph command#


The graph command generates graphical representations of the topology.

Two graphing options are available:


The HTML based graph is the default graphing option. The topology will be graphed and served online using the embedded web server.

The graph is created by rendering a Go HTML template against a data structure containing the topology name as well as a json string where 2 lists are present: nodes and links .

nodes contains data about the lab nodes, such as name, kind, type, image, state, IP addresses,...

links contains the list of links defined by source node and target node, as well as the endpoint names

example of the json string
  "nodes": [
      "name": "node1-1",
      "image": "srlinux:20.6.1-286",
      "kind": "srl",
      "group": "tier-1",
      "state": "running/Up 21 seconds",
      "ipv4_address": "",
      "ipv6_address": "2001:172:23:23::3/80"
    // omitted rest of nodes
  "links": [
      "source": "node1-2",
      "source_endpoint": "e1-1",
      "target": "node2-1",
      "target_endpoint": "e1-2"
      "source": "node2-1",
      "source_endpoint": "e1-4",
      "target": "node3-1",
      "target_endpoint": "e1-1"
    // the rest is omitted

Within the template, Javascript libraries such as d3js directed force graph or vis.js network can be used to generate custom topology graphs.

containerlab comes with a (minimalistic) default template using d3js.

After the graph generation, it's possible to move the nodes to a desired position and export the graph in PNG format.



When graph command is called without the --srv flag, containerlab will generate a graph description file in dot format.

The dot file can be used to view the graphical representation of the topology either by rendering the dot file into a PNG file or using online dot viewer.

Online vs offline graphing#

When HTML graph option is used, containerlab will try to build the topology graph by inspecting the running containers which are part of the lab. This essentially means, that the lab must be running. Although this method provides some additional details (like IP addresses), it is not always convenient to run a lab to see its graph.

The other option is to use the topology file solely to build the graph. This is done by adding --offline flag.

If --offline flag was not provided and no containers were found matching the lab name, containerlab will use the topo file only (as if offline mode was set).


containerlab [global-flags] graph [local-flags]



With the global --topo | -t flag a user sets the path to the topology file that will be used to get the nodes of a lab.


The --srv flag allows a user to customize the HTTP address and port for the web server. Default value is :50080.

A single path / is served, where the graph is generated based on either a default template or on the template supplied using --template.


The --template flag allows to customize the HTML based graph by supplying a user defined template that will be rendered and exposed on the address specified by --srv.


With --dot flag provided containerlab will generate the dot file instead of serving the topology with embedded HTTP server.


# render a graph from running lab or topo file if lab is not running#
# using HTML graph option with default server address :50080
containerlab graph --topo /path/to/topo1.clab.yml

# start an http server on :3002 where topo1 graph will be rendered using a custom template my_template.html
containerlab graph --topo /path/to/topo1.clab.yml --srv ":3002" --template my_template.html

Back to top