The Container Needs Docker, So Mount the Socket and Run --privileged?
A CI job needs to build images and a teammate wants to bind-mount the Docker socket and run --privileged to fix permission errors. Defend the safe approach.
Answer key reviewed by Branko Petric
Read first: Docker Security Best Practices
Your decision
A CI job inside a container needs to build images, and a teammate says just bind-mount /var/run/docker.sock and run the job with --privileged so it can do whatever it needs. What do you do, and why?
The situation
A containerized CI runner needs to build and push Docker images as part of the pipeline. The build step keeps failing with permission errors because there is no Docker daemon reachable from inside the job container, and the pipeline is blocked.
Context
The CI jobs run in ephemeral containers on a shared runner host. A teammate proposes the quick fix: bind-mount the host Docker socket (/var/run/docker.sock) into the job container and add --privileged so it can do whatever it needs. The pipeline also builds pull requests from outside contributors, so code you do not control runs on this same runner.
Worked interview answers
- Docker Scenario Based Interview Questions: Diagnose First, Then Defend the Fix
Docker scenario based interview questions, worked: a 1.6GB image, --no-cache, a mounted Docker socket, exit code 137, a secret in a layer and container DNS.
- Scenario Based DevOps Interview Questions, With Worked Answers
Scenario based DevOps interview questions for Linux, Docker, CI/CD, Git and AWS, with first commands, the interviewer's pushback, and weak vs strong answers.
Related challenges
- 1.6GB Docker Image, 8-Minute Builds. Add Runners?
Your image is huge and every code change rebuilds from scratch. A teammate wants to just add more CI runners. Defend how you actually fix it.
- The Build Is Slow, So Let's Just Add --no-cache to CI?
CI Docker builds crept to 11 minutes and once shipped a stale dependency. A teammate wants --no-cache on every build. Defend what you actually do first.
- Your CI Has Keys to Prod and Pulls Unpinned Deps
CI pulls unpinned dependencies, runs them, and holds prod credentials. A teammate says just add a vulnerability scanner. Defend a real hardening plan.
- Deploy From CI: Paste AWS Keys Into GitHub Secrets?
Your GitHub Actions pipeline needs to deploy to AWS. A teammate wants to paste a long-lived IAM access key into repo secrets. Defend the better option.