docker.recipes

Jenkins CI Server

intermediate

Jenkins CI/CD server with Docker support.

Overview

Jenkins is an open-source automation server that has become the backbone of continuous integration and continuous deployment (CI/CD) pipelines since its creation in 2011. Originally developed as Hudson by Kohsuke Kawaguchi at Sun Microsystems, Jenkins revolutionized software development by automating the build, test, and deployment processes. With over 1,800 plugins available, Jenkins can integrate with virtually any tool in the development ecosystem, making it the Swiss Army knife of DevOps automation. This Docker configuration provides a production-ready Jenkins instance with Docker-in-Docker capabilities, enabling containerized build processes and modern CI/CD workflows. The setup includes proper volume mounting for persistence, network isolation for security, and Docker socket access for container management within Jenkins pipelines. By running Jenkins in Docker with Docker support, teams can create sophisticated build pipelines that leverage containerization while maintaining consistency across different environments. This stack is ideal for development teams transitioning to containerized workflows, DevOps engineers managing complex multi-service applications, and organizations requiring robust automation with the flexibility to integrate custom tools and processes through Jenkins' extensive plugin ecosystem.

Key Features

  • Pipeline as Code support through Jenkinsfile for version-controlled build definitions
  • Access to 1,800+ plugins for integration with virtually any development tool
  • Docker-in-Docker capabilities for containerized builds and deployments
  • Blue Ocean modern UI for visual pipeline creation and monitoring
  • Distributed build support with Jenkins agents for horizontal scaling
  • Built-in credentials management system for secure API keys and certificates
  • Matrix builds for testing across multiple configurations simultaneously
  • Shared pipeline libraries for reusable code across multiple projects

Common Use Cases

  • 1Automated testing and deployment of microservices with Docker container builds
  • 2Legacy application modernization with gradual CI/CD pipeline implementation
  • 3Multi-platform software builds targeting different operating systems and architectures
  • 4Integration testing environments that spin up temporary Docker containers
  • 5Automated security scanning and compliance checks in regulated industries
  • 6Custom automation workflows for infrastructure provisioning and management
  • 7Code quality gates with automated static analysis and test coverage reporting

Prerequisites

  • Minimum 2GB RAM allocated to Docker (Jenkins requires 512MB minimum, 2GB+ recommended)
  • Docker Engine with privileged container support enabled
  • Port 8080 and 50000 available on the host system
  • Basic understanding of Jenkins pipeline concepts and Groovy scripting
  • Familiarity with Docker commands for troubleshooting container issues
  • Administrative access to retrieve initial Jenkins admin password from container logs

For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms

docker-compose.yml

docker-compose.yml
1services:
2 jenkins:
3 image: jenkins/jenkins:lts
4 container_name: jenkins
5 restart: unless-stopped
6 privileged: true
7 user: root
8 ports:
9 - "${JENKINS_PORT:-8080}:8080"
10 - "50000:50000"
11 environment:
12 - DOCKER_HOST=tcp://docker:2376
13 - DOCKER_CERT_PATH=/certs/client
14 - DOCKER_TLS_VERIFY=1
15 volumes:
16 - jenkins_home:/var/jenkins_home
17 - /var/run/docker.sock:/var/run/docker.sock
18 networks:
19 - jenkins-network
20
21volumes:
22 jenkins_home:
23
24networks:
25 jenkins-network:
26 driver: bridge

.env Template

.env
1# Jenkins
2JENKINS_PORT=8080

Usage Notes

  1. 1Jenkins at http://localhost:8080
  2. 2Get initial password from logs
  3. 3Install suggested plugins
  4. 4Docker socket mounted for DIND

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 jenkins:
5 image: jenkins/jenkins:lts
6 container_name: jenkins
7 restart: unless-stopped
8 privileged: true
9 user: root
10 ports:
11 - "${JENKINS_PORT:-8080}:8080"
12 - "50000:50000"
13 environment:
14 - DOCKER_HOST=tcp://docker:2376
15 - DOCKER_CERT_PATH=/certs/client
16 - DOCKER_TLS_VERIFY=1
17 volumes:
18 - jenkins_home:/var/jenkins_home
19 - /var/run/docker.sock:/var/run/docker.sock
20 networks:
21 - jenkins-network
22
23volumes:
24 jenkins_home:
25
26networks:
27 jenkins-network:
28 driver: bridge
29EOF
30
31# 2. Create the .env file
32cat > .env << 'EOF'
33# Jenkins
34JENKINS_PORT=8080
35EOF
36
37# 3. Start the services
38docker compose up -d
39
40# 4. View logs
41docker compose logs -f

One-Liner

Run this command to download and set up the recipe in one step:

terminal
1curl -fsSL https://docker.recipes/api/recipes/jenkins-ci/run | bash

Troubleshooting

  • Jenkins shows 'Offline' status: Check if port 8080 is accessible and not blocked by firewall rules
  • Docker builds failing with permission denied: Verify Docker socket mount and that Jenkins runs with root privileges
  • Initial setup wizard not loading: Retrieve admin password using 'docker logs jenkins' and check container startup completion
  • Plugins failing to install: Increase Jenkins memory allocation and verify internet connectivity from container
  • Build agents not connecting on port 50000: Ensure port 50000 is exposed and accessible through network security groups
  • Out of disk space errors: Monitor jenkins_home volume usage and implement log rotation policies

Community Notes

Loading...
Loading notes...

Download Recipe Kit

Get all files in a ready-to-deploy package

Includes docker-compose.yml, .env template, README, and license

Ad Space