Jenkins Declarative Pipeline with Docker
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 trainwithshubham/django-app:latest'
}
}
}
Task-01
Create a docker-integrated Jenkins declarative pipeline
In Jenkins, Click on “New Item”, create a new pipeline job, and select "Pipeline" as the project type
Use the above-given syntax using
sh
inside the stage blockIn the configuration, In the pipeline script section, define your stages, steps, and parameters.
Save and run the pipeline. You should see the pipeline execute each stage and run your application inside a Docker container.
You will face errors in case of running a job twice, as the docker container will be already created, so for that do task 2
Task-02
Create a docker-integrated Jenkins declarative pipeline using the
docker
groovy syntax inside the stage block.We can solve the error with the help of docker-compose, by modifying the script using docker-compose down and up commands.
Thank you for reading my blog! Happy Learning!!!😊
Subscribe to my newsletter
Read articles from Suraj barik directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Suraj barik
Suraj barik
I'm Suraj Barik Aspiring DevOps Engineer with Hands-on experience in Automating,Shell Scripting, Supporting in AWS, management, CI/CD, and DevOps processes.