Jenkins: Install with Docker and Create Your First Pipeline
Edited by Dev Kilaru, Senior Data Analyst. How we make our content
Introduction
Jenkins is a long-established, self-hosted automation server with a huge plugin ecosystem, still widely used for CI/CD, especially in larger organizations. Unlike GitHub Actions, you run and maintain it yourself. This lesson starts Jenkins in Docker, completes the setup wizard, and runs a first pipeline.
Prerequisites
- Docker installed and running
- A basic understanding of CI/CD
Step-by-Step Guide
Step 1: Check the requirements
Current Jenkins LTS releases need Java 21 or 25, and Java 17 is no longer supported. The official Docker images bundle the right Java, so using the jenkins/jenkins LTS image with a JDK 21 tag avoids setting up Java yourself. Always check the Jenkins documentation for the current LTS version and Java support.
Step 2: Run Jenkins in Docker
This starts the LTS image with its data in a named volume, so your jobs and settings survive restarts. Port 8080 serves the web interface, and port 50000 is only for inbound build agents, so you can omit it on a single machine. This simple setup is fine for learning; building Docker images from inside Jenkins needs extra setup described in the official documentation.
docker run -d --name jenkins \
--restart=on-failure \
-p 8080:8080 -p 50000:50000 \
-v jenkins_home:/var/jenkins_home \
jenkins/jenkins:lts-jdk21Step 3: Unlock Jenkins
Open http://localhost:8080. The Unlock Jenkins page asks for an administrator password that Jenkins generated on first start. Find it in the container's logs, between rows of asterisks, or read it from the data folder, then paste it into the Administrator password box and click Continue.
docker logs jenkins
# or:
docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPasswordStep 4: Finish the setup wizard
On the Customize Jenkins page, choose Install suggested plugins, which installs a sensible default set. Then create your first admin user and click Save and Finish, and then Start using Jenkins. Manage plugins later under Manage Jenkins, then Plugins, and keep them updated, since plugins are a common source of security fixes.
Step 5: Create and run a pipeline job
Click New Item, enter a name, choose Pipeline, and click OK. In the Pipeline section, set Definition to Pipeline script and paste a Jenkinsfile. Save, then click Build Now. Open the build in Build History and choose Console Output to read the log.
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
stage('Test') {
steps {
echo 'Testing...'
}
}
}
}FAQs
- Jenkins or GitHub Actions: which should I learn?
- GitHub Actions is simpler for projects hosted on GitHub, with no server to run. Jenkins is very flexible and common in organizations with existing installations or special requirements. The pipeline concepts transfer between them.
- Is it safe to expose my Jenkins to the internet?
- Only with care. Jenkins can run arbitrary commands, so use HTTPS, strong authentication, least-privilege access, and prompt updates. Never leave a default or open installation reachable from the internet.
Summary
Run the Jenkins LTS image with a named volume, unlock it with the generated password, install the suggested plugins, create an admin user, and run a Pipeline job. Read the console output and keep Jenkins and its plugins updated.
Comments
Log in or create a free account to join the discussion.