Skip to content

Feature: interactive exec #3155

Description

@pimvanpelt

On a machine with many containerlab instances (for example, as used in trainings or workshops), the container names can become quite long, in order to be globally unique in Docker. When multiple vendors are used, lab users constantly have to remember which containers can be SSH'd to and with which username:password, and which do not offer SSH and need to be connected via TTY.

I propose a simple tool called dc (which stands for docker-connect) which lists available containers, optionally filtered by --topo and --name flags, and allows the user to shorthand with a container-name sub-string, to invoke docker exec with the most appropriate shell given a container name.

Example:

pim@summer:~/src/zanog26-containerlab-workshop/afternoon/server$ clab tools dc
12:21:31 INFO Parsing & checking topology file=srv.clab.yml
available containers:
  zanog-srv-vpp1 (git.ipng.ch/ipng/vpp-containerlab:latest-amd64)
  zanog-srv-vpp2 (git.ipng.ch/ipng/vpp-containerlab:latest-amd64)
  zanog-srv-web (git.ipng.ch/ipng/clab-webserver:latest)

pim@summer:~/src/zanog26-containerlab-workshop/afternoon/server$ clab tools dc vpp
12:24:17 INFO Parsing & checking topology file=srv.clab.yml
ambiguous argument, matched more than one container:
  zanog-srv-vpp2 (git.ipng.ch/ipng/vpp-containerlab:latest-amd64)
  zanog-srv-vpp1 (git.ipng.ch/ipng/vpp-containerlab:latest-amd64)
          
   ERROR  
          
  Ambiguous container name "vpp".                                                                                     

pim@summer:~/src/zanog26-containerlab-workshop/afternoon/server$ clab tools dc vpp1
12:24:19 INFO Parsing & checking topology file=srv.clab.yml
root@vpp1:/# 

The 'most appropriate shell' is configured by matching the container's image-name. It can be overridden by the --shell flag.

Compare:

pim@summer:~/src/zanog26-containerlab-workshop/afternoon/server$ clab tools dc vpp1
12:24:19 INFO Parsing & checking topology file=srv.clab.yml
root@vpp1:/# ip -br a
lo               UNKNOWN        127.0.0.1/8 ::1/128 
loop0            UP             10.0.0.1/32 2001:db8::1/128 fe80::dcad:ff:fe00:0/64 
eth1             UNKNOWN        192.0.2.254/24 2001:db8:8298::fe/64 fe80::a8c1:abff:fe60:ec0d/64 
eth2             UNKNOWN        10.0.0.16/31 2001:db8:0:1::1/64 fe80::a8c1:abff:fe5e:2bb8/64 

With:

pim@summer:~/src/zanog26-containerlab-workshop/afternoon/server$ clab tools dc vpp1 --shell /bin/bash
12:25:59 INFO Parsing & checking topology file=srv.clab.yml
root@vpp1:/# ip -br a
lo               UNKNOWN        127.0.0.1/8 ::1/128 
eth0@if4352      UP             172.20.0.4/22 3ff1:172:20::4/64 fe80::b0ad:43ff:fea2:cef1/64 
eth1@if4349      UP             fe80::a8c1:abff:fe60:ec0d/64 
eth2@if4356      UP             fe80::a8c1:abff:fe5e:2bb8/64 

The first one executes the 'default' shell which is nsenter --net=/run/netns/dataplane /bin/bash while the second one executes a custom shell which drops into the default network namespace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions