docker run -v /var/run/docker.sock:/var/run/docker.sock jenkins/jenkins
What is the main effect of mounting the Docker socket inside the Jenkins container?
Mounting /var/run/docker.sock inside the Jenkins container gives Jenkins direct access to the host's Docker daemon. This means Jenkins can run Docker commands that affect the host, such as building or running containers.
docker run -v /var/run/docker.sock:/var/run/docker.sock jenkins/jenkins
But Jenkins jobs fail with permission denied errors when running Docker commands. What is the most likely cause?
The Docker socket file /var/run/docker.sock is owned by the docker group on the host. If the Jenkins user inside the container is not part of this group or lacks permissions, Docker commands will fail with permission denied errors.
/var/jenkins_home on the host?The correct syntax for mounting volumes is -v host_path:container_path. Option D mounts both the Docker socket and the Jenkins home directory correctly.
Docker-in-Docker runs a separate Docker daemon inside the Jenkins container, isolating it from the host's Docker daemon and reducing security risks compared to mounting the host's Docker socket.
First, verify the Docker daemon is running on the host (4). Then run Jenkins with the Docker socket mounted (1). Next, ensure Jenkins user permissions (3). Finally, configure Jenkins pipeline to use Docker commands (2).