Easy CI/CD Setup with Jenkins, Docker & Git
What You'll Need
Before we start, make sure you have:
- Basic GitHub knowledge
- A Linux server (or VM)
- Some Docker experience
Overview
Hey! If you're a junior developer looking to learn CI/CD, you're in the right place! This guide is specifically written for beginners who want to understand how to automate their deployment process.
Today I'm going to walk you through setting up CI/CD with Docker and Jenkins from scratch. Don't worry if this sounds intimidating - it's actually pretty straightforward! With modern tools (and a bit of AI help), anyone can build a solid pipeline without too much hassle.
So, without further ado, let's dive in!
Step 1: GitHub Setup
First things first - let's get your GitHub ready:
- Create a repository on GitHub for your project
- Go to Settings β Developer settings β Personal access tokens
- Generate a new token (make sure to save it somewhere safe - you'll need it later!)
Step 2: Local Development
Now let's work on your local machine:
- Write your code - use whatever language you prefer (Java, Python, Go, Node.js - anything works!)
- Create a Dockerfile for building your app
- Test the Docker build locally to make sure everything works:
docker build -t your-app:latest .
If it builds successfully, you're good to go!
Step 3: Server Setup
Time to prep your deployment server:
- Update your package manager:
sudo apt update -y
- Install Docker and docker-compose:
sudo apt install docker.io docker-compose-plugin -y
- Create a docker-compose file for Jenkins:
Here's a simple setup that works:
services:
jenkins:
image: jenkins/jenkins:lts
user: root # avoid permission errors
ports:
- "8080:8080"
volumes:
- ./jenkins_home:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
Important tips:
- The volumes setup ensures your Jenkins config persists across restarts
- Mounting the Docker socket lets Jenkins control Docker on the host
- Pro tip: Store this compose file in a GitHub repo for version control!
Step 4: Jenkins Configuration
Alright, now for the fun part - setting up Jenkins:
-
Add GitHub credentials:
- Use that personal access token you created earlier
- Store it securely in Jenkins credentials manager
Create a Pipeline with these stages:
Your pipeline should look something like this (don't worry, you can use AI to help write the Jenkinsfile!):
- Checkout - Pull your code from GitHub
- Build - Build your Docker image
- Login - Authenticate with Docker Hub
- Push - Push your image to Docker Hub
- SSH to server - Connect to your deployment server
-
Deploy - Run your updated container
- Set up automatic triggering:
You have two options here:
Option A: Webhooks (if you have a public IP)
- Simply create a webhook in your GitHub repository settings
- Jenkins will automatically trigger the build as soon as you push code
- This is the cleanest approach!
Option B: Poll SCM (if you don't have a public IP)
- Set up a Jenkins cron schedule to check for updates (e.g., every 2 minutes)
- Make sure you have a Jenkinsfile in your repository
- Not as instant as webhooks, but gets the job done
Bonus: Easy Log Viewing with Dozzle
Want to see your container logs easily? Let me introduce you to Dozzle - it's a game changer!
- Go to the Dozzle homepage
- Copy the docker installation command
- Run it on your Linux server:
docker run -d --name dozzle -v /var/run/docker.sock:/var/run/docker.sock -p 9999:9999 amir20/dozzle:latest
That's it! Now you can view all your container logs in a nice web interface at http://your-server:9999 π
No more SSH-ing into your server just to check logs!
Wrapping Up
Congrats! You now have a fully working CI/CD pipeline. Every time you push code to GitHub, Jenkins will automatically build and deploy your app. Pretty cool, right?
The best part? Once it's set up, you can pretty much forget about it and focus on writing code. Your deployments will just... happen.
Happy coding! π
Top comments (0)