What is your go-to sequence to harden and verify a container before shipping?
AdvancedProductionRapid-Fire Commands
Answer
hadolint Dockerfile
docker build -t app:test .
trivy image --exit-code 1 --severity HIGH,CRITICAL app:test
docker run -d --name t --read-only --tmpfs /tmp --cap-drop ALL \
--security-opt no-new-privileges --user 10001 --pids-limit 200 --memory 512m -p 8080:8080 app:test
sleep 5; curl -fsS localhost:8080/healthz; docker inspect -f '{{.State.Status}} {{.State.OOMKilled}}' t
docker rm -f t
If it runs healthy under those constraints, it will run under any sane production policy.
More on Rapid-Fire Commands
Run a container in the background with a name, a port mapping and an env var.BeginnerShow only running container names and their images.BeginnerFollow the last 50 lines of logs with timestamps.BeginnerGet a shell in a running container, as root, even if the image sets USER.BeginnerStop and remove every exited container.BeginnerShow which files a container changed relative to its image.Beginner