Challenge - 5 Problems
Docker Agent Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Output of Jenkins pipeline with Docker agent
What will be the output of this Jenkins pipeline snippet when run on a Jenkins master with Docker installed?
Jenkins
pipeline {
agent {
docker {
image 'alpine:3.14'
args '-v /tmp:/tmp'
}
}
stages {
stage('Test') {
steps {
sh 'echo Hello from inside Docker'
}
}
}
}Attempts:
2 left
💡 Hint
The pipeline uses a Docker agent with Alpine image and runs a simple echo command inside the container.
✗ Incorrect
The pipeline runs the shell command inside the Alpine Docker container, so the output is the echo statement's text.
❓ Configuration
intermediate2:00remaining
Correct Docker agent syntax in Jenkinsfile
Which Jenkinsfile snippet correctly defines a Docker agent that uses the 'node:18' image and mounts the host directory '/data' to '/app/data' inside the container?
Attempts:
2 left
💡 Hint
Docker volume mount syntax uses '-v' flag.
✗ Incorrect
The correct Docker run argument to mount a volume is '-v host_path:container_path'.
❓ Troubleshoot
advanced2:00remaining
Troubleshooting Docker agent permission error
A Jenkins pipeline using a Docker agent fails with the error: 'permission denied while trying to connect to the Docker daemon socket'. What is the most likely cause?
Attempts:
2 left
💡 Hint
Accessing Docker requires permission to the Docker socket file.
✗ Incorrect
The error indicates Jenkins cannot access the Docker daemon socket, usually due to user permission issues.
🔀 Workflow
advanced2:00remaining
Jenkins pipeline with multiple Docker agents
In a Jenkins pipeline, you want to run one stage inside a Python Docker container and another stage inside a Node.js Docker container. Which pipeline structure correctly achieves this?
Attempts:
2 left
💡 Hint
Use 'agent none' at top level to specify agents per stage.
✗ Incorrect
Defining 'agent none' at pipeline level allows each stage to specify its own Docker agent.
✅ Best Practice
expert2:00remaining
Best practice for Docker agent cleanup in Jenkins
Which approach ensures Docker containers used as Jenkins agents are properly cleaned up after pipeline execution to avoid resource leaks?
Attempts:
2 left
💡 Hint
Jenkins Docker plugin can manage container lifecycle automatically.
✗ Incorrect
Setting 'reuseNode false' tells Jenkins to remove the container after the build, preventing leftover containers.