DEV Community

Krisha Arya
Krisha Arya

Posted on

πŸš€ DevOps Project Journey: Docker + Jenkins Setup

πŸ› οΈ 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! πŸ™Œ

Top comments (0)