Skip to content

Latest commit

 

History

History
 
 

container-collection

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Container Collection Example

This is a basic example that uses the container-collection package ("github.com/inspektor-gadget/inspektor-gadget/pkg/container-collection") to print a message when a container is created or removed.

How to build

$ go build .

How to run

Start the example in one terminal. It'll print the already existing containers:

$ sudo ./container-collection
Container added: "local-registry" pid 6135

In another terminal, run a container:

$ docker run --name hi -rm ubuntu /bin/bash -c "echo hi && sleep 2"
hi

The previous terminal will contain messages indicating the creation and removal of this container:

$ sudo ./container-collection
Container added: "local-registry" pid 6135
Container added: "hi" pid 130258
Container removed: "hi" pid 130258

More information

The kube-container-collection example contains a more complex setup using this package.