Skip to content

Commit da8186e

Browse files
James Stone TIL sync botjamesmstone
authored andcommitted
Wed 18 Jun 2025 13:43:16 CEST
1 parent c9d1142 commit da8186e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

containers/sh-sidecars.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
> Having tools in a container might sometimes be useful for different debugging. Just exec into it and start the diagnostics. With a distroless/minimized image, it's not that easy. What we can do instead is attach a sidecar container:
3+
>
4+
```sh
5+
docker run \
6+
--rm \
7+
-it \
8+
--pid=container:<container id> \
9+
--net=container:<container id> \
10+
--cap-add sys_admin \
11+
alpine \
12+
sh
13+
```
14+
15+
16+
from: [Minimal containers using Nix](https://tmp.bearblog.dev/minimal-containers-using-nix/)
17+
18+
19+
20+
This starts an Alpine container that attaches to the same PID and network namespaces, giving you visibility into what's running inside the original container.
21+
22+
23+
To make this easier, you can define a Bash function:
24+
25+
```bash
26+
sidecar-sh() {
27+
local target_container="$1"
28+
local container_id
29+
container_id=$(docker inspect --format '{{.Id}}' "$target_container")
30+
31+
docker run --rm -it \
32+
--pid=container:"$container_id" \
33+
--net=container:"$container_id" \
34+
--cap-add sys_admin \
35+
alpine sh
36+
}
37+
38+
```
39+
40+
**Usage:** `sidecar-sh <container-name>` and you will be alongside your process

0 commit comments

Comments
 (0)