Skip to content

Instantly share code, notes, and snippets.

# try to run more than the amount of PIDs that are allowed
# - we should see `fork()` syscall erroring:
docker run --pids-limit 100 cirocosta/stress pid -n 300
Starting to spawn 300 blocking children
Error:
Fork returned -1.
File: src/pid.c
docker run -d --name nginx --pids-limit 100 nginx:alpine
d9bd65d2e98ec...
find /sys/fs/cgroup/ -name "d9bd65d2e98*"
/sys/fs/cgroup/cpu,cpuacct/docker/d9bd65d2e...
/sys/fs/cgroup/cpuset/docker/d9bd65d2e98ec4...
/sys/fs/cgroup/devices/docker/d9bd65d2e98ec...
/sys/fs/cgroup/pids/docker/d9bd65d2e98ec418...
/sys/fs/cgroup/freezer/docker/d9bd65d2e98ec...
/sys/fs/cgroup/perf_event/docker/d9bd65d2e9...
# let's get the ID of the container. Docker uses that ID
# to name things in the host to we can probably use it to
# find the cgroup created for the container
# under the parent docker cgroup
docker ps
CONTAINER ID IMAGE COMMAND
a730051832e7 cirocosta/stress "pid -n 300"
# Having the prefix in hands, let's search for it under the
# mountpoint for cgroups in our system
# Run a container that will spawn 300 processes.
docker run cirocosta/stress pid -n 300
Starting to spawn 300 blocking children
[1] Waiting for SIGINT
# Open another window and see that we have 300
# PIDS
docker stats
CONTAINER  … MEM USAGE / LIMIT PIDS
a730051832   … 21.02MiB / 1.951GiB 300
docker-runc exec -t ece80(...)bc19 sh
/mnt
└── cloudstor
└── max
└── my-volume-1 # the volume I created!
└── my-file
docker plugin inspect <plugin-id>
...
"PidHost": false,
"PropagatedMount": "/mnt", # this is interesting
"User": {},
...
# docker plugin ls --no-trunc
ID NAME DESCR...
ece80624f9b17(...) cloudstor:aws cloud...
cat /run/docker/libcontainerd/ece806249b1(...)/config.json | jq
{
"ociVersion": "1.0.0-rc2-dev",
"platform": {
ID PID STATUS BUNDLE CREATED
148f2281926ba14...4ce411a 240 running /run/docker/libcontainerd/14... 2017-06-25T...
1a173adde3f3fa5...f9e9058 328 running /run/docker/libcontainerd/1a... 2017-06-19T...
2b116e7b84d9082...3663419 186 running /run/docker/libcontainerd/2b... 2017-06-25T...
4e9c20abee6c851...62cb601 286 running /run/docker/libcontainerd/4e... 2017-06-19T...
6b1b5f85756c8d5...77c657c 910 running /run/docker/libcontainerd/6b... 2017-06-22T...
6d45ca793639cb0...abeca02 275 running /run/docker/libcontainerd/6d... 2017-06-19T...
6f7280987c5dd33...4d82a05 801 running /run/docker/libcontainerd/6f... 2017-06-22T...
a975e5d841ad124...9cdd046 295 running /run/docker/libcontainerd/a9... 2017-06-19T...
ece80624f9b178c...74cbc19 302 running /run/docker/libcontainerd/ec... 2017-06-19T...
docker run \
--rm \ # remove the container after we run it
-it \ # add a tty and start it w/ interactive mode
--privileged \ # grant all permissions to the container
--pid=host \ # share the host PID space
justincormack/nsenter1 \ # magic 🎩
/bin/sh # start /bin/sh
docker4x/shell-aws:17.05.0-ce-aws2 0.0.0.0:22->22/tcp shell-aws
docker4x/l4controller-aws:17.05.0-ce-aws2 l4controller-aws
docker4x/meta-aws:17.05.0-ce-aws2 <internal-ip>:9024->8080/tcp meta-aws
docker4x/guide-aws:17.05.0-ce-aws2 guide-aws