0
0
Jenkinsdevops~20 mins

Docker agents for isolation in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Docker Agent Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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'
      }
    }
  }
}
AHello from inside Docker
BError: Docker daemon not found
CPermission denied when accessing /tmp
DPipeline skipped due to missing image
Attempts:
2 left
💡 Hint
The pipeline uses a Docker agent with Alpine image and runs a simple echo command inside the container.
Configuration
intermediate
2: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?
A
agent {
  docker {
    image 'node:18'
    args '-v /data:/app/data'
  }
}
B
agent {
  docker {
    image 'node:18'
    args '--mount /data:/app/data'
  }
}
C
agent {
  docker {
    image 'node:18'
    args '--volume /data:/app/data'
  }
}
D
agent {
  docker {
    image 'node:18'
    args '-m /data:/app/data'
  }
}
Attempts:
2 left
💡 Hint
Docker volume mount syntax uses '-v' flag.
Troubleshoot
advanced
2: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?
AThe Docker image specified does not exist in the registry.
BThe Jenkins user does not have permission to access the Docker socket on the host.
CThe Jenkinsfile syntax for the Docker agent is incorrect.
DThe Docker daemon is running but out of disk space.
Attempts:
2 left
💡 Hint
Accessing Docker requires permission to the Docker socket file.
🔀 Workflow
advanced
2: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?
A
pipeline {
  agent { docker { image 'node:18' } }
  stages {
    stage('Python Stage') {
      agent { docker { image 'python:3.10' } }
      steps { sh 'python --version' }
    }
    stage('Node Stage') {
      steps { sh 'node --version' }
    }
  }
}
B
pipeline {
  agent { docker { image 'python:3.10' } }
  stages {
    stage('Python Stage') {
      steps { sh 'python --version' }
    }
    stage('Node Stage') {
      agent { docker { image 'node:18' } }
      steps { sh 'node --version' }
    }
  }
}
C
pipeline {
  agent none
  stages {
    stage('Python Stage') {
      agent { docker { image 'python:3.10' } }
      steps { sh 'python --version' }
    }
    stage('Node Stage') {
      agent { docker { image 'node:18' } }
      steps { sh 'node --version' }
    }
  }
}
D
pipeline {
  agent none
  stages {
    stage('Python Stage') {
      steps { sh 'docker run python:3.10 python --version' }
    }
    stage('Node Stage') {
      steps { sh 'docker run node:18 node --version' }
    }
  }
}
Attempts:
2 left
💡 Hint
Use 'agent none' at top level to specify agents per stage.
Best Practice
expert
2: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?
AManually run 'docker rm -f' commands in pipeline steps after each stage.
BConfigure Jenkins to use 'docker' agents with 'alwaysPull true' to refresh images each run.
CUse 'agent any' and run Docker containers outside Jenkins to avoid cleanup issues.
DUse the 'docker' agent with 'reuseNode false' and rely on Jenkins to remove containers automatically.
Attempts:
2 left
💡 Hint
Jenkins Docker plugin can manage container lifecycle automatically.