🛠️ Project Overview
This blog is a walkthrough of my hands-on experience in setting up a Jenkins automation pipeline using Docker. The aim was to containerize a project and integrate Jenkins for continuous integration and delivery (CI/CD). I will explain the entire process from Docker setup to Jenkins configuration, highlight key commands, and document the challenges and confusions I faced.
🐳 Docker Setup
📁 Step 1: Project Directory Structure
your-project/
│
├── frontend/ (React App)
│ └── Dockerfile
│
├── backend/ (Node.js App)
│ └── Dockerfile
│
├── docker-compose.yml
├── Jenkinsfile
✅ Prerequisites Check
Ensure the following are installed:
-> Docker 🐳
-> Docker Compose (docker compose version)
-> Jenkins (running as a container or installed locally)
-> Ports not already in use (check the ones in your docker-compose.yml)
🧾 Step 2: Dockerfile
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 5002
CMD ["npm", "start"]
FROM node:18-alpine as build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx:stable-alpine
COPY --from=build /app/build /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80 3002
CMD ["nginx", "-g", "daemon off;"]
🧰 Step 3: docker-compose.yml
version: "3.8"
services:
backend:
image:
ports:
- "5002:5002" //any port u want
frontend:
image:
ports:
- "3002:80"//any port you want
🚀 Step 4: Run Docker
docker-compose up --build
⚠️ Challenges Faced with Docker
- Docker not recognizing updated files → resolved by rebuilding the image
- Volume permissions → checked and fixed using
chmod
🔍 Commands I Referenced
docker ps
docker stop
docker rm
docker volume ls
docker volume rm
🔧 Jenkins Setup with Docker
🛠️ Step 1: Pull Jenkins Image and Run
docker run -d -p 8081:8080 -p 50000:50000 \
-v jenkins_home:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
--name jenkins \
jenkins/jenkins:lts
📝 Step 2: Get Initial Admin Password
docker exec -it jenkins cat /var/jenkins_home/secrets/initialAdminPassword
🔄 Restart Jenkins if Needed
docker restart jenkins
🛑 Stop and Remove Jenkins
docker stop jenkins
docker rm jenkins
docker volume rm jenkins_home
⚙️ Jenkinsfile Example
pipeline {
agent any
stages {
stage('Clone from GitHub') {
steps {
git branch: 'main', url: 'https://github.com/Aryagithubk/educart_docker.git'
}
}
stage('Build Backend') {
steps {
sh 'docker build -t ./backend'
}
}
stage('Build Frontend') {
steps {
sh 'docker build -t ./educart'
}
}
stage('Push Images') {
steps {
sh 'echo "" | docker login -u --password-stdin'
sh 'docker push '
sh 'docker push '
}
}
stage('Deploy to Swarm') {
steps {
sh 'docker-compose up --build -d'
}
}
}
}
😵 Confusions & Debugging
-
Couldn’t install
nano
inside Jenkins container → switched tovim
- Permission denied while updating apt → switched to root user to install packages
- Jenkins login loop → fixed by deleting and recreating Jenkins container/volume
🔍 Helpful Commands I Referred
docker exec -it jenkins bash
apt-get update
apt-get install -y vim
vim /var/jenkins_home/users/admin/config.xml
🧠 What I Learned
- How to isolate and run services using Docker
- CI/CD integration with Jenkins
- Handling Jenkins configuration manually in files
- Importance of clean volumes and environment consistency
📸 **
**
Your final jenkins dashboard will look like this. Now we need to configure this dashboard as well. I will tell about this next time.
🧾 Conclusion
This was a complete experience from setting up a Dockerized environment to implementing a Jenkins CI/CD pipeline. While it came with its fair share of hurdles, it turned out to be a valuable learning process.
Thanks for reading! Bye Bye! 🙌