If you want a Jenkins server that is portable enough to survive developer tantrums and cloud provider mood swings then running Jenkins inside Docker is the pragmatic choice. This guide walks through pulling the official Jenkins image starting a container with persistent storage creating a basic pipeline and keeping your Jenkinsfile in source control so pipeline changes are reviewed like actual code.
Containers give you repeatable builds and faster onboarding. For DevOps teams the benefits are obvious automation friendly portable and less time spent fixing environment drift. You get a fully functional Jenkins server without wrestling with system packages or mysterious dependency conflicts.
Use the official image to avoid getting surprised by unofficial forks. The LTS tag is a sensible default for most teams.
docker pull jenkins/jenkins:lts
Mount a host or named volume to keep job history plugin data and config across container restarts. Expose the web UI and the agent port if you plan to use Jenkins agents in containers later.
docker run -d -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home --name jenkins jenkins/jenkins:lts
On first start Jenkins asks for an initial admin password. You can fetch it from the container logs or by reading the file inside the running container.
docker logs jenkins
# or
docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
Use the web UI to create an admin user and install the recommended plugin set unless you like custom pain. The recommended set covers most common SCM and pipeline needs.
In the Jenkins UI create a new pipeline project and point it to your repository or paste a pipeline script. The best practice is to put a declarative Jenkinsfile next to your code so CI lives with the repo and goes through code review.
pipeline {
agent any
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build') {
steps {
sh 'mvn -B -DskipTests package'
}
}
stage('Test') {
steps {
sh 'mvn test'
}
}
}
post {
always {
archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true
junit '**/target/surefire-reports/*.xml'
}
}
}
Trigger a build from the dashboard or configure a webhook from your SCM provider to kick off runs on push. Watch the console output for each stage. Jenkins will tell you exactly which command failed and why the build had a temper tantrum.
That is the minimal path to run Jenkins in a container and get a working CI CD pipeline up fast. It is repeatable portable and friendly for teams practicing DevOps. Now go add automation and let your CI do the boring work while you take all the credit.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.