Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

cntr

> DevOps
Open source

A container debugging tool based on FUSE

950 stars0 likes0 views
WebsiteGitHub

About

A container debugging tool based on FUSE

cntr

Say no to $ apt install vim in containers! cntr is a replacement for docker exec that brings all your developers tools with you. This is done by mounting the file system from one container or the host into the target container by creating a nested container with the help of the Linux mount API. This allows to ship minimal runtime image in production and limit the surface for exploits.

Requirements: Linux kernel 5.2 or later (uses fsopen/fsmount mount API, added in 5.2).

Cntr was also published in Usenix ATC 2018. See bibtex for citation.

Note: The academic paper describes the original FUSE-based architecture. As of version 2.0.0, cntr has been rewritten to use the Linux mount API instead of FUSE, significantly improving performance and security while maintaining the same user interface and capabilities.

What you get

…

What this means for you:

  • Use your familiar tools (vim, gdb, strace) even if they're not in the container
  • Access container files at /var/lib/cntr/etc/, /var/lib/cntr/var/, etc.
  • Same network, process tree, and environment as the container
  • Original container keeps running normally - your changes only affect your session
  • Run native container commands with cntr exec

Demo

In this two minute recording you learn all the basics of cntr:

Features

  • For convenience cntr supports container names/identifier for the following container engines natively:
    • docker
    • podman
    • LXC
    • LXD
    • systemd-nspawn
    • containerd
    • k3s (via containerd/crictl)
  • For other container engines cntr also takes process ids (PIDs) instead of container names.

Installation

Cntr by design is only able to run on Linux.

System Requirements:

  • Linux kernel 5.2 or later

For distribution packagers: See PACKAGING.md for packaging guidelines and examples.

Pre-build static-linked binary

For linux x86_64 we build static binaries for every release. More platforms can added on request. See the release tab for pre-build tarballs. At runtime only commandline utils of the container engine in questions are required.

Build from source

All you need for compilation is rust + cargo. Checkout rustup.rs on how to get a working rust toolchain. Then run:

Either:

bash
$ cargo install cntr

Or the latest master:

bash
$ cargo install --git https://github.com/Mic92/cntr

For offline builds we also provided a tarball with all dependencies bundled here for compilation with cargo-vendor.

Usage

At a high-level cntr provides two subcommands: attach and exec:

  • attach: Allows you to attach to a container with your own native shell/commands. Cntr will mount the container at /var/lib/cntr (configurable via CNTR_BASE_DIR environment variable). The container itself will run unaffected as the mount changes are not visible to container processes.
    • Example: cntr attach where container_id can be a container identifier or process id (see examples below).
  • exec: Run commands from the container filesystem.
    • Usage: cntr exec --
    • Example: cntr exec where container_id can be a container identifier or process id Since container commands might need their native mount layout at /, exec chroots to the container and sets up the container's environment.

Note: Cntr needs to run on the same host as the container. It does not work if the container is running in a virtual machine while cntr is running on the hypervisor.

bash
$ cntr --help
cntr 1.6.1
by Jörg Thalheim 

Enter or execute in container

USAGE:
    cntr 

SUBCOMMANDS:
    attach    Enter container with mount overlay
    exec      Execute command in container
    help      Print help
    version   Print version
…
…

Docker

1: Find out the container name/container id:

bash
$ docker run --name boxbusy -ti busybox
$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
55a93d71b53b        busybox             "sh"                22 seconds ago      Up 20 seconds                           boxbusy

Either provide a container id...

…

...or the container name.

To execute container native commands, use cntr exec:

bash
$ cntr exec boxbusy -- sh -c 'busybox | head -1'

You can also use Dockerfile from this repo to build a docker container with cntr:

bash
$ docker build -f Dockerfile . -t cntr
# boxbusy here is the name of the target container to attach to
$ docker run --pid=host --privileged=true -v /var/run/docker.sock:/var/run/docker.sock -ti --rm cntr attach boxbusy /bin/sh

Podman

See docker usage, just replace docker with the podman command.

LXD

1: Create a container and start it

bash
$ lxc image import images:/alpine/edge
$ lxc launch images:alpine/edge
$ lxc list
+-----------------+---------+------+------+------------+-----------+
|      NAME       |  STATE  | IPV4 | IPV6 |    TYPE    | SNAPSHOTS |
+-----------------+---------+------+------+------------+-----------+
| amazed-sailfish | RUNNING |      |      | PERSISTENT | 0         |
+-----------------+---------+------+------+------------+-----------+

2: Attach to the container with cntr

bash
$ cntr attach amazed-sailfish
$ cat etc/hostname
amazed-sailfish

LXC

1: Create a container and start it

bash
$ lxc-create --name ubuntu -t download -- -d ubuntu -r xenial -a amd64
$ lxc-start --name ubuntu -F
...
Ubuntu 16.04.4 LTS ubuntu console
ubuntu login:
$ lxc-ls
ubuntu

2: Attach to container with cntr:

bash
$ cntr attach ubuntu
[root@ubuntu2:/var/lib/cntr]# cat etc/os-release
NAME="Ubuntu"
VERSION="16.04.4 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.4 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

systemd-nspawn

1: Start container

bash
$ wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-root.tar.xz
$ mkdir /var/lib/machines/ubuntu
$ tar -xf ubuntu-16.04-server-cloudimg-amd64-root.tar.xz -C /var/lib/machines/ubuntu
$ systemd-nspawn -b -M ubuntu
$ machinectl list
MACHINE CLASS     SERVICE        OS     VERSION ADDRESSES
ubuntu  container systemd-nspawn ubuntu 16.04   -

2: Attach

bash
$ cntr attach ubuntu

Generic process id

The minimal information needed by cntr is the process id of a container process you want to attach to.

bash
# Did you now chromium uses namespaces too?
$ ps aux | grep 'chromium --type=renderer'
joerg    17498 11.7  1.0 1394504 174256 ?      Sl   15:16   0:08 /usr/bin/chromium

In this case 17498 is the pid we are looking for.

…

Containerd

For containerd integration the ctr binary is required. You can get a binary by running:

bash
$ GOPATH=$(mktemp -d)
$ go get github.com/containerd/containerd/cmd/ctr
$ $GOPATH/bin/ctr --help

Put the resulting ctr binary in your $PATH

1: Start container

bash
$ ctr images pull docker.io/library/busybox:latest
$ ctr run docker.io/library/busybox:latest boxbusy
$ ctr tasks lists
TASK        PID      STATUS
boxbusy    24310    RUNNING

2: Attach

bash
$ cntr attach boxbusy

It's also possible to run cntr from a container itself. This repository contains a example Dockerfile for that:

bash
$ docker build -f Dockerfile.example . -t cntr
$ docker save cntr > cntr.tar
$ ctr images import --base-name cntr ./cntr.tar

In this example we attach to containerd by process id. The process id of a task is given in ctr tasks list.

bash
$ ctr run --privileged --with-ns pid:/proc/1/ns/pid --tty docker.io/library/cntr:latest cntr /usr/bin/cntr attach 31523 /bin/sh

To resolve containerd names one also would need to add the ctr binary (~12mb) to the Dockerfile.

Additional Config

Custom Mount Directory

By default, cntr mounts containers at /var/lib/cntr. You can customize this location using the CNTR_BASE_DIR environment variable:

bash
$ export CNTR_BASE_DIR=/custom/path
$ cntr attach mycontainer
[root@container:/custom/path]#

This is particularly useful for:

  • Testing with temporary directories
  • Systems where /var/lib/cntr is not suitable
  • Isolating multiple cntr sessions

AppArmor Profile Control

By default, cntr automatically inherits the AppArmor security profile from the target container. You can control this behavior using the --apparmor flag:

bash
# Default behavior - automatically inherit AppArmor profile
$ cntr attach mycontainer

# Explicitly enable AppArmor profile inheritance
$ cntr attach --apparmor auto mycontainer

# Disable AppArmor profile inheritance
$ cntr attach --apparmor off mycontainer
$ cntr exec --apparmor off mycontainer -- /bin/sh

When to use --apparmor off:

  • Troubleshooting AppArmor-related issues
  • Running tools that conflict with the container's AppArmor profile
  • Systems where AppArmor is not properly configured
  • Development and debugging scenarios where you need unrestricted access

Note: On systems without AppArmor enabled, this flag has no effect. The flag is available for both attach and exec commands.

Running with File Capabilities (setcap)

By default, cntr requires root privileges. However, you can use Linux file capabilities to run cntr without full root access:

bash
# Grant required capabilities to cntr binary
$ sudo setcap 'cap_sys_admin,cap_sys_chroot=ep' /usr/local/bin/cntr

# Enable setcap mode (required due to Linux security restrictions)
$ export CNTR_ALLOW_SETCAP=1

# Now run cntr as a regular user
$ cntr attach mycontainer

Required capabilities:

Capability Purpose
CAP_SYS_ADMIN Namespace operations (unshare, setns), mount operations
CAP_SYS_CHROOT chroot() for cntr exec command
CAP_SYS_PTRACE Only needed when attaching to containers owned by a different user

Why CNTR_ALLOW_SETCAP=1 is required:

When Linux runs a binary with file capabilities, it marks the process as "non-dumpable" for security. This prevents the process from accessing /proc/self/ns/*, which cntr needs to function. Setting CNTR_ALLOW_SETCAP=1 tells cntr to re-enable dumpable mode via prctl(PR_SET_DUMPABLE, 1).

Security considerations:

Enabling dumpable mode has security implications:

  • Core dumps may expose privileged memory contents
  • Other processes running as the same user can ptrace() the cntr process

The risk is mitigated by cntr's short-lived nature (attach → exec → exit), but you should understand these tradeoffs before using this feature.

How it works

Cntr is container-agnostic: Instead of interfacing with container engines, it implements the underlying operating system API. It treats every container as a group of processes, that it can inherit properties from.

Cntr inherits the following container properties:

  • Namespaces (mount, uts, pid, net, cgroup, ipc)
  • Cgroups
  • Apparamor/selinux
  • Capabilities
  • User/group ids
  • Environment variables
  • The following files: /etc/passwd, /etc/hostname, /etc/hosts, /etc/resolv.conf

Related projects

  • nsenter
    • Only covers linux namespaces and the user is limited to tools installed in the containers
  • toolbox
    • Does attach from a container to the host, this is the opposite of what Cntr is doing

Bibtex

We published a paper with all technical details about Cntr i

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rustbuild-with-buildbotdockerlxcrkt

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
CategoryDevOps
PricingOpen source

> Related tools

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理