#90DaysOfDevops | Day 27

Rajendra PatilRajendra Patil
2 min read

Use your Docker Build and Run Knowledge

docker build - you can use sh 'docker build . -t <tag>' in your pipeline stage block to run the docker build command. (Make sure you have docker installed with correct permissions.

docker run: You can use sh 'docker run -d <image>' in your pipeline stage block to build the container.

How will the stages look

stages {
        stage('Build') {
            steps {
                sh 'docker build -t devops/django-app:latest'
            }
        }
    }

Task-01:
1)Create a docker-integrated Jenkins declarative pipeline
Step 1: In Jenkins, Click on New Item, and select "Pipeline" as the new job type.

Image description

Image description

Step 2: Configure Pipeline:

After selecting Pipeline, you will select a section where you can define the pipeline configuration.

Pipeline Script: This is a simple script editor where you can write your pipeline script directly.

Pipeline from SCM: You can define your pipeline script in a version control repository (e.g., Git) and have Jenkins fetch and execute it.

Image description

Image description

Step 3: Now go to Jenkins Pipeline and Build the Pipeline.

Image description

Step 4: Access your application on the browser as shown below

Image description

Step 5: It's working. Now if we run the job again it will fail because Jenkins tries to build a container but as we already have a running container with the same name and the same exposed port, creates a conflict. To see this click on build now and see the console output.

Image description

Task-02:

1)Create a docker-integrated Jenkins declarative pipeline using the docker groovy syntax inside the stage block.

We already have a docker-compose.yml configuration file in our repository, so we have to use docker-compose commands to up and down the service containers.

Image description

Click on Save and then click on Build Now

Image description

Image description

Happy Learning....

0
Subscribe to my newsletter

Read articles from Rajendra Patil directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rajendra Patil
Rajendra Patil