>_ IzzyLab

Hands-on task

This task is step 7 of the course “Containers from the inside: namespaces and cgroups”

A container without a shell: nsenter instead of docker exec

medium~12 min

The ledger accounting service runs in a Docker container built from a minimal image: inside there's only the binary and its libraries — no sh, no ip, no curl, so docker exec won't help here. After an overnight experiment the service stopped passing its health check: it listens on 127.0.0.1:8080 inside the container, and /health no longer opens.

Find the cause and fix the live container: you may not restart or recreate it — it holds an unwritten queue in memory. Take the tools from the host: nsenter, ip, curl.

What you'll practise:
  • nsenter
  • namespaces
  • docker
  • ip

Topic breakdown

To the kernel a container is an ordinary host process placed into namespaces of its own. That's why you can get into a container without Docker: nsenter -t <PID> runs a command in the namespaces of a process — network (-n), mount (-m), PID (-p) and others, as you choose. If you enter only the network namespace, the filesystem stays the host's — so every host tool works, even when the image has neither a shell nor utilities. This is how "distroless" images and containers where docker exec is useless get debugged. docker inspect -f '{{.State.Pid}}' shows the PID of the container's main process.

What's checked

  1. The ledger container is running and hasn't been restarted
  2. The /health check answers from inside the container

What it looks like