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.
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.
Step 3: Now go to Jenkins Pipeline and Build the Pipeline.
Step 4: Access your application on the browser as shown below
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.
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.
Click on Save and then click on Build Now
Top comments (0)