Set up Jenkins using Docker by pulling the official jenkins/jenkins:lts image and running it with the necessary port mappings and volume mounts for persistent data and Docker access
Running Jenkins in a Docker container is the quickest way to get started, as it eliminates manual dependency installations and provides isolation. The official Jenkins image includes everything needed to run Jenkins, and you can customize it by mounting volumes for persistent storage and accessing the Docker daemon from within the container .
For Jenkins to build and run Docker containers as part of your CI/CD pipelines, it needs access to the Docker daemon. The cleanest approach is to mount the host's Docker socket into the Jenkins container. This gives Jenkins the ability to execute Docker commands without running Docker-in-Docker .
After starting the container, Jenkins generates an initial admin password. You'll need this to unlock Jenkins during first-time setup. Once unlocked, you can install recommended plugins and create your admin user .
Pull the image: docker pull jenkins/jenkins:lts
Run with persistence: Use the -v jenkins_home:/var/jenkins_home flag to ensure your configurations survive container restarts or upgrades
Map ports: Always map port 8080 for the web UI and optionally port 50000 for agent connections
Add Docker access: Mount the Docker socket (-v /var/run/docker.sock:/var/run/docker.sock) to enable Jenkins pipelines to build and run containers
Retrieve the password: Run docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword to get the initial unlock key
For a more manageable setup, especially when you need to add other services like Nginx or databases, use Docker Compose. Create a docker-compose.yml file that defines the Jenkins service with all the necessary volume mounts and port mappings. This is particularly useful for version-controlling your Jenkins configuration and simplifying restarts .
If Jenkins cannot execute Docker commands, verify that the Docker socket is correctly mounted and that permissions are set. For hosts with AppArmor or SELinux restrictions, you may need additional configuration. Also ensure that the Jenkins user inside the container has the necessary permissions—the official image runs as user jenkins (UID 1000), and the mounted socket must be readable by that UID .