Complete Jenkins server setup using Docker Compose with Jenkins Configuration as Code (JCasC), pre-installed plugins, multi-architecture support, and Docker-in-Docker capabilities
This repository demonstrates how to create a Jenkins server using Docker Compose and Jenkins Configuration as Code (JCasC). The setup includes plugins, and supports both ARM and AMD architectures.
setup-jenkins.shUse the setup-jenkins.sh script for automated setup:
./setup-jenkins.sh
The script will:
.env file| Action | Command |
|---|---|
| Start Jenkins | docker compose up -d |
| View logs | docker compose logs -f jenkins |
| Stop Jenkins | docker compose down |
| Restart Jenkins | docker compose restart jenkins |
| Remove volumes (⚠️ deletes data) | docker compose down -v |
The Jenkins configuration is defined in jenkins.yaml. This file includes:
For detailed explanation: See JENKINS_CONFIG.md
The docker-compose.yaml file orchestrates the Jenkins container and includes:
For detailed explanation: See DOCKER_COMPOSE_CONFIG.md
| Variable | Source | Purpose |
|---|---|---|
JENKINS_ADMIN_PASSWORD |
Docker Compose secret | Admin user password (loaded from secrets/jenkins_admin_password) |
JENKINS_DEVOPS_PASSWORD |
Docker Compose secret | DevOps user password (loaded from secrets/jenkins_devops_password) |
JENKINS_URL |
.env file |
Public URL of Jenkins instance (required, e.g., http://localhost:8080/) |
JENKINS_ADMIN_EMAIL |
.env file |
Admin email address (required, e.g., admin@example.com) |
DOCKER_SOCK_PATH |
.env file |
Docker socket path on host (automatically detected by setup-jenkins.sh) |
Edit jenkins.yaml to customize:
Important: Passwords are managed through Docker Compose secrets stored in the secrets/ directory. To change passwords, regenerate the secret files and restart Jenkins:
openssl rand -base64 32 > secrets/jenkins_admin_password
openssl rand -base64 32 > secrets/jenkins_devops_password
docker compose restart jenkins
Docker Cloud is a Jenkins feature that allows Jenkins to dynamically provision Docker containers as build agents on demand, rather than using static build agents.
Instead of maintaining permanent build agents, Jenkins can:
The Docker Cloud is configured in jenkins.yaml with the following settings:
jenkins/inbound-agent:lts-jdk21 for build agentsdocker labelpipeline {
agent {
label 'docker'
}
stages {
stage('Build') {
steps {
sh 'echo "Building in Docker agent"'
}
}
}
}
This setup includes Docker-in-Docker support, allowing Jenkins pipelines to build Docker images. The Docker socket is mounted from the host, enabling Jenkins to use the host's Docker daemon.
Note: The Jenkins container runs as the jenkins user (non-root) with docker group membership for secure Docker socket access. For production environments, consider using Docker-in-Docker containers or a separate Docker daemon.
jenkins_home: Persistent storage for Jenkins data, configurations, and build historyjenkins.yaml: Mounted as read-only configuration file for JCasCJenkins runs on a custom Docker network (jenkins-network) for service isolation. This allows for future expansion with additional services (databases, reverse proxies, etc.) that can communicate using service names as hostnames.
Project overview, features, quick start guide, and usage instructions
Detailed explanation of JCasC configuration file and all settings
Complete guide to Docker Compose setup, volumes, networks, and secrets
Product requirements document with setup instructions and file structure
Comprehensive unit tests for Jenkins configuration, authentication, and permissions
URL: http://localhost:8080
After starting Jenkins with Docker Compose, access the web interface at the configured URL (default: http://localhost:8080).
Two pre-configured users are available:
adminsecrets/jenkins_admin_passwordOverall/Administer)devopssecrets/jenkins_devops_passwordOverall/Administer)To view passwords:
cat secrets/jenkins_admin_password
cat secrets/jenkins_devops_password
URL: http://localhost:8080/blue
Blue Ocean provides a modern, intuitive user interface for Jenkins pipelines. It should be accessible after installation.
http://localhost:8080/bluesecrets/ directory (git-ignored). Never commit plain-text passwords to version control.jenkins user (non-root) with docker group membership for secure Docker socket access.jenkins.yaml) is mounted as read-only to prevent accidental modification.setup-jenkins.sh automatically generates secure passwords using openssl rand -base64 32secrets/ directory and .env file are git-ignoredjenkins.yamlThe Docker socket should be owned by root:docker with permissions srw-rw---- (typically mode 0660). Check with:
ls -l $DOCKER_SOCK_PATH
Or check your .env file for the detected path.
Common issues and solutions:
docker compose logs jenkins, verify Docker socket permissions, ensure ports 8080 and 50000 are not in usejenkins.yaml syntaxdocker buildx create --name multiarch --useFor detailed troubleshooting information, see the Troubleshooting section in the README.
This repository includes comprehensive unit tests for the Jenkins configuration, covering:
For detailed information about running and maintaining the tests, see TEST_README.md.
GitHub Repository: docker-compose-and-jenkins-casc
This project is licensed under the MIT License.
See the LICENSE file for details.
Copyright (c) 2025 Tal Orlik