🚀 DevOps Project Journey: Docker + Jenkins Setup
Krisha Arya

Krisha Arya @krisha_arya_55

About: Enthusiastic

Joined:
Sep 5, 2024

🚀 DevOps Project Journey: Docker + Jenkins Setup

Publish Date: Apr 23
0 0

🛠️ 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

Enter fullscreen mode Exit fullscreen mode

✅ 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"]
Enter fullscreen mode Exit fullscreen mode
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;"]
Enter fullscreen mode Exit fullscreen mode

🧰 Step 3: docker-compose.yml

version: "3.8"

services:
  backend:
    image: <your-image-name>
    ports:
      - "5002:5002" //any port u want

  frontend:
    image: <your-image-name>
    ports:
      - "3002:80"//any port you want
Enter fullscreen mode Exit fullscreen mode

🚀 Step 4: Run Docker

docker-compose up --build
Enter fullscreen mode Exit fullscreen mode

⚠️ 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 <container_id>
docker rm <container_id>
docker volume ls
docker volume rm <volume_name>
Enter fullscreen mode Exit fullscreen mode

🔧 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
Enter fullscreen mode Exit fullscreen mode

📝 Step 2: Get Initial Admin Password

docker exec -it jenkins cat /var/jenkins_home/secrets/initialAdminPassword
Enter fullscreen mode Exit fullscreen mode

🔄 Restart Jenkins if Needed

docker restart jenkins
Enter fullscreen mode Exit fullscreen mode

🛑 Stop and Remove Jenkins

docker stop jenkins
docker rm jenkins
docker volume rm jenkins_home
Enter fullscreen mode Exit fullscreen mode

⚙️ 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 <your-image-name> ./backend'
      }
    }

    stage('Build Frontend') {
      steps {
        sh 'docker build -t <your-image-name> ./educart'
      }
    }

    stage('Push Images') {
  steps {
    sh 'echo "<password>" | docker login -u <username> --password-stdin'
    sh 'docker push <your-backend-image-name>'
    sh 'docker push <your-frontend-image-name>'
  }
}


    stage('Deploy to Swarm') {
      steps {
        sh 'docker-compose up --build -d'
      }
    }
  }
}

Enter fullscreen mode Exit fullscreen mode

😵 Confusions & Debugging

  • Couldn’t install nano inside Jenkins container → switched to vim
  • 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
Enter fullscreen mode Exit fullscreen mode

🧠 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

📸 **
Image description

**
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! 🙌

Comments 0 total

    Add comment