Introduction
Sometimes you want your Jenkins build to run inside a Docker container. This helps keep your build environment clean and consistent. Using a Docker agent in a Jenkinsfile lets Jenkins run your build steps inside a Docker container automatically.
When you want to run your build in a specific environment without installing tools on the Jenkins server.
When you need to isolate builds to avoid conflicts between different projects.
When you want to use the same environment locally and in Jenkins for consistency.
When your build requires software that is only available inside a Docker image.
When you want to easily update or change the build environment by switching Docker images.