Day 26 was all about a Declarative pipeline, now its time to level up things, let's integrate Docker and your Jenkins declarative pipeline
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 rjthapaa/django-app:latest'
}
}
}
Task-01
Create a docker-integrated Jenkins declarative pipeline
Use the above-given syntax using
sh
inside the stage blockYou will face errors in case of running a job twice, as the docker container will be already created, so for that do task 2
Prerequisites :
Jenkins, Docker and Docker-Compose must be installed in your system
Start Jenkins instance in AWS and Log in to your Jenkins dashboard.
Open Jenkins and create a Pipeline project
Give it a description and select GitHub project, provide url
Go to the pipeline section and add the script to build and run the container using docker commands
Click on apply and save
Click on Build now
Console output
Access the Todo application
Task-02
Create a docker-integrated Jenkins declarative pipeline using the
docker
groovy syntax inside the stage block.You won't face errors, you can Follow this documentation
Complete your previous projects using this Declarative pipeline approach
In case of any issues feel free to post on any Groups, Discord or Telegram
Go the Jenkins Declarative Pipeline Project with Docker project and click configure
Nagivate to Pipeline script
Replace docker run command with docker compose
click on apply and Build now
Here by using docker-compose down command, wea re deleted all the existing container and then creating a new one by docker-compose up
Console output
Access the application