Skip to content

pouyaarjomandi/jenkins-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jenkins Docker

A local Jenkins environment for running CI/CD pipelines with Docker support.

Overview

This project runs Jenkins inside a Docker container using Docker Compose.

Jenkins can access the host Docker daemon through the Docker socket:

/var/run/docker.sock

This allows Jenkins pipelines to run Docker commands such as docker build, docker run, and docker push.

This setup uses the host Docker socket. It is not a full Docker-in-Docker setup.

Project Structure

jenkins-docker/
├── .gitignore
├── Dockerfile
├── README.md
├── docker-compose.yml
└── plugins.txt

Features

  • Jenkins LTS running in Docker
  • Docker CLI available inside the Jenkins container
  • Python 3, pip, and venv for Python-based pipelines
  • curl for health checks
  • Jenkins plugins installed from plugins.txt
  • Persistent Jenkins data using a named Docker volume
  • Access to the host Docker daemon through /var/run/docker.sock

Prerequisites

  • Docker
  • Docker Compose

On macOS, Docker Desktop must be running before starting Jenkins.

Start Jenkins

Build and start Jenkins:

docker compose up -d --build

Open Jenkins in the browser:

http://localhost:8080

Get the Initial Admin Password

docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword

Use this password to complete the initial Jenkins setup.

Docker Access

The Jenkins container mounts the host Docker socket:

- /var/run/docker.sock:/var/run/docker.sock

The container is also added to group 0:

group_add:
  - "0"

This works for this local Docker Desktop setup. On some Linux systems, the Docker socket group may be different and group_add may need to be adjusted.

To verify Docker access from inside the Jenkins container:

docker exec -it jenkins docker ps

If the command lists running containers, Jenkins can access Docker.

Common Commands

Start Jenkins:

docker compose up -d

Rebuild and start Jenkins:

docker compose up -d --build

Stop Jenkins:

docker compose stop

Restart Jenkins:

docker compose restart

View logs:

docker compose logs -f

Remove the Jenkins container:

docker compose down

Remove the Jenkins container and delete Jenkins data:

docker compose down -v

Usage Note

This setup mounts the host Docker socket so Jenkins can run Docker commands from inside the container.

It is designed for local development, CI/CD practice, and portfolio projects.

Companion Project

This Jenkins environment can be used with the companion FastAPI project:

python-app-jenkins

The companion project contains a FastAPI application and a Jenkins pipeline that runs tests, builds a Docker image, pushes it to Docker Hub, deploys the container, and verifies the /health endpoint.

About

Dockerized Jenkins CI server with Docker-out-of-Docker (DooD) support for container-based pipelines.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages