0
0
Jenkinsdevops~5 mins

Docker agent in Jenkinsfile - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a Docker agent in a Jenkinsfile?
A Docker agent in a Jenkinsfile is a way to run Jenkins pipeline steps inside a Docker container. It helps create a consistent environment for builds.
Click to reveal answer
beginner
How do you specify a Docker agent in a Jenkins declarative pipeline?
Use the agent { docker { image 'image-name' } } syntax inside the Jenkinsfile to run steps inside the specified Docker image.
Click to reveal answer
beginner
Why use a Docker agent in Jenkins pipelines?
Using a Docker agent ensures the build runs in a clean, isolated environment with all required tools, avoiding conflicts and making builds reproducible.
Click to reveal answer
intermediate
What happens if the Docker image specified in the Jenkinsfile is not available on the Jenkins host?
Jenkins will try to pull the Docker image from the configured Docker registry before running the build inside the container.
Click to reveal answer
beginner
Show a simple Jenkinsfile snippet using a Docker agent with the image 'python:3.12'.
pipeline {
  agent {
    docker { image 'python:3.12' }
  }
  stages {
    stage('Test') {
      steps {
        sh 'python --version'
      }
    }
  }
}
Click to reveal answer
What does the 'agent { docker { image "node:18" } }' block do in a Jenkinsfile?
APushes the 'node:18' image to Docker Hub.
BBuilds a Docker image named 'node:18'.
CRuns pipeline steps inside a Docker container using the 'node:18' image.
DStarts a Docker daemon on the Jenkins server.
If the Docker image is not found locally, what does Jenkins do?
APulls the image from the Docker registry.
BFails the build immediately.
CBuilds the image from a Dockerfile automatically.
DSkips the Docker agent and runs on the Jenkins host.
Which Jenkinsfile syntax is correct to use a Docker agent?
Aagent { docker { image 'ubuntu:20.04' } }
Bagent { shell 'docker run ubuntu' }
Cagent { label 'docker' }
Dagent { dockerfile 'Dockerfile' }
What is a key benefit of using Docker agents in Jenkins pipelines?
AUnlimited build concurrency.
BFaster network speed.
CAutomatic code deployment.
DConsistent and isolated build environments.
Can you run multiple stages inside the same Docker agent container in a Jenkins pipeline?
AOnly if you use scripted pipeline syntax.
BYes, all stages share the same Docker container if agent is defined at pipeline level.
CNo, each stage creates a new container.
DOnly if you disable Docker caching.
Explain how to use a Docker agent in a Jenkinsfile and why it is useful.
Think about how Docker containers help keep builds clean and repeatable.
You got /3 concepts.
    Describe what happens when Jenkins runs a pipeline with a Docker agent but the image is not present locally.
    Consider how Docker handles missing images on a host.
    You got /3 concepts.