🎯 Automating Docker Workflows with Jenkins: A Step-by-Step Guide πŸš€

Β·

2 min read

πŸš€ Task 1: Jenkins Freestyle Project for Your Dockerized App 🐳

🌟 Step 1: Set Up Jenkins Agent for Your App

  1. Install Jenkins on Your Machine πŸ› οΈ:

    • Deploy Jenkins using Docker:

        docker run -d -p 8080:8080 -p 50000:50000 --name jenkins-server -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts
      
    • Access Jenkins at http://localhost:8080 🌐.

  2. Install the Necessary Plugins ⚑:

    • Go to Manage Jenkins > Plugin Manager.

    • Install these must-have plugins:

      • 🐳 Docker Pipeline

      • 🧰 Git

      • πŸ” SSH Agent

  3. Create an Agent (a.k.a. Jenkins Node πŸ€–):

    • Navigate to Manage Jenkins > Manage Nodes and Clouds > New Node.

    • Configure:

      • πŸ“‚ Remote Directory

      • 🏷️ Labels for Agent Selection

      • πŸ”— Launch Method (e.g., SSH).


🎯 Step 2: Build the Freestyle Project

  1. Create the Project πŸ› οΈ:

    • Go to New Item > Name it something cool like "DockerAppBuilder" > Select Freestyle Project > Click OK.
  2. Connect Your Repository πŸ”—:

    • In the Source Code Management section:

      • Select Git.

      • Enter the URL of your app repository πŸ“¦.

  3. Add Build Steps βš™οΈ:

    • In the Build section:

      • Step 1: Add a shell script to build your Docker image 🐳:

          docker build -t my-awesome-app-image .
        

        πŸ› οΈ This step creates your app image. Cool, right?

      • Step 2: Add another shell script to run your Docker container 🚒:

          docker run -d --name my-awesome-app-container -p 80:80 my-awesome-app-image
        

        🌐 Your app will now be live!

  4. Save and Test 🏁:

    • Hit Save and then click Build Now ▢️ to see your app come to life. 🌟

🌟 Task 2: Jenkins Project with Docker Compose Magic πŸ§™β€β™‚οΈ

πŸš€ Step 1: Create the Jenkins Project

  1. Create Another Project πŸ› οΈ:

    • Go to New Item > Name it "ComposeWizard" ✨ > Select Freestyle Project > Click OK.
  2. Link Your Repo πŸ”—:

    • In the Source Code Management section:

      • Select Git and provide the repo URL with your docker-compose.yml file πŸ—‚οΈ.

🎯 Step 2: Docker Compose Setup

  1. Add Build Steps πŸ”§:

    • Step 1: Add a shell script to bring up your containers 🚒:

        docker-compose up -d
      

      ✨ This will spin up your app and database effortlessly!

    • Step 2: Add a cleanup step 🧹:

        docker-compose down
      

      🧽 Tidy up those containers when you’re done!

  2. Save and Build πŸš€:

    • Click Save and then Build Now ▢️ to see your multi-container setup in action!

Β