You need to build a Docker image from a pipeline without giving the build access to the host Docker socket.
AdvancedScenarioJenkins Pipelines and Agents
Answer
Situation read → Mounting /var/run/docker.sock gives root-equivalent access to the node.
What I'd do →
- Use daemonless builders: Kaniko, BuildKit rootless, or Buildah, running as a container in a Kubernetes agent pod.
- Example container step:
/kaniko/executor --context $WORKSPACE --dockerfile Dockerfile --destination $REG/app:$TAG. - Authenticate to the registry with a mounted pull-secret or short-lived credentials, and isolate build pods in their own namespace with a restricted PodSecurity level.
Why → Anyone who can run a pipeline could otherwise escape to the host through the Docker socket.
Interview tip → Mention that Kaniko is archived upstream by Google, so evaluate BuildKit or Buildah for new setups.
More on Jenkins Pipelines and Agents
Your team still builds jobs by clicking through Freestyle jobs in the Jenkins UI. A new service is starting. What do you set up instead?BeginnerA Jenkins build takes 40 minutes because unit tests, linting and security scans run one after another. How do you speed it up?BeginnerBuilds queue for 20 minutes during the morning rush, but the Jenkins nodes are mostly idle at night. What do you do?IntermediateA build works on agent A but fails on agent B with "command not found: mvn". How do you stop this class of problem?BeginnerYou need a pipeline to build a branch automatically on push without polling. How do you wire it?BeginnerOnly the main branch should deploy; feature branches and PRs should only build and test. How do you express this?Beginner