Skip to main content

Command Palette

Search for a command to run...

๐Ÿš€ #๐——๐—ฎ๐˜†๐Ÿฎ๐Ÿฏ - Jenkins Freestyle Project for DevOps Engineers | #๐Ÿต๐Ÿฌ๐——๐—ฎ๐˜†๐˜€๐—ข๐—ณ๐——๐—ฒ๐˜ƒ๐—ข๐—ฝ๐˜€

Published
โ€ข2 min read
A

DevOps | Cloud Practitioner | AWS | GIT | Kubernetes | Terraform | ArgoCD | Gitlab

Completing Tasks with Jenkins and Docker Integration ๐Ÿš€

Hereโ€™s a step-by-step guide to complete the above tasks and integrate Jenkins with Docker for building and running containers efficiently.


Task 1: Build and Run a Docker Container in a Jenkins Freestyle Project

Step 1: Create a Jenkins Agent

  • Install and configure a Jenkins agent on the system where Docker is installed.

  • Make sure Docker is accessible by the Jenkins user.

Step 2: Create a Freestyle Project

  1. Open Jenkins and click on "New Item".

  2. Enter the project name (e.g., "Docker-Build-Run") and select Freestyle Project.

  3. Click OK to create the project.

Step 3: Configure Build Steps

  • Step 1: Build the Docker Image
    In the Build section, add an "Execute Shell" build step with the following command:

      docker build -t your-app-image:latest .
    
  • Step 2: Run the Docker Container
    Add another "Execute Shell" build step with the following command:

      docker run -d --name your-app-container -p 8080:8080 your-app-image:latest
    

Step 4: Save and Test the Pipeline

  • Save the project and click Build Now to test.

  • Jenkins will now:

    1. Build the Docker image for your app.

    2. Run the container using the image created.


Task 2: Automating docker-compose Commands in Jenkins

Step 1: Create a Freestyle Project for Docker Compose

  1. In Jenkins, click "New Item".

  2. Enter the project name (e.g., "Docker-Compose-Project") and select Freestyle Project.

  3. Click OK to create the project.

Step 2: Configure Build Steps

  • Step 1: Run docker-compose up
    In the Build section, add an "Execute Shell" build step with:

      docker-compose up -d
    
  • Step 2: Cleanup with docker-compose down
    Add a post-build action or another "Execute Shell" step for cleanup:

      docker-compose down
    

Step 3: Save and Test

  • Save the project and click Build Now to test.

  • Jenkins will now:

    1. Start multiple containers using docker-compose up.

    2. Stop and remove them using docker-compose down.


What Youโ€™ll Achieve

  1. Automated Docker image builds and container deployment via Jenkins.

  2. Streamlined multi-container app deployment using Docker Compose.

  3. Improved DevOps workflow with less manual intervention.

More from this blog

DevOps Projects and Blog

69 posts