Deploying Jenkins using Docker on an Azure Linux Virtual Machine provides a practical way to establish a self-hosted Continuous Integration and Continuous Deployment (CI/CD) environment. Docker isolates Jenkins from the host operating system, helping reduce dependency conflicts and making the deployment easier to manage and update.
This guide walks through the process of installing Docker, deploying Jenkins, configuring the required firewall and Azure network rules, and retrieving the initial Jenkins administrator password.
Prerequisites
Before starting, ensure you have:
An Azure Linux Virtual Machine, such as an Ubuntu or Debian-based server.
Administrative (
sudo) access to the server through SSH.Access to the Azure Portal to configure networking rules.
A public IP address for the VM if Jenkins needs to be accessed externally.
Step 1: Install Docker on Your Linux Server
If Docker is already installed on your virtual machine, you can skip to Step 2.
For an Ubuntu or Debian-based server, install Docker using the following commands:
# Update package list and install prerequisites
sudo apt update
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
# Add Docker's official GPG key and repository
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install Docker Engine
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io
# Start and enable Docker service
sudo systemctl start docker
sudo systemctl enable docker
# Add your current user to the docker group
sudo usermod -aG docker $USER
newgrp docker
Verify the installation:
docker --version
If Docker is already configured on the server, proceed directly to the Jenkins deployment.
Step 2: Deploy Jenkins Using Docker
Jenkins stores important information such as pipelines, configurations, plugins, and build history. A persistent Docker volume ensures that this data remains available if the Jenkins container is stopped, removed, or recreated.
Create a dedicated Docker volume:
docker volume create jenkins_home
Next, start the Jenkins LTS container:
docker run -d \
--name jenkins \
-p 8080:8080 \
-p 50000:50000 \
-v jenkins_home:/var/jenkins_home \
--restart unless-stopped \
jenkins/jenkins:lts
Key Flag Breakdown
-d: Runs the container in detached mode.--name jenkins: Assigns the container the namejenkins.-p 8080:8080: Maps port8080on the host to Jenkins' web interface inside the container.-p 50000:50000: Maps port50000, which can be used for inbound Jenkins agent connections.-v jenkins_home:/var/jenkins_home: Mounts the persistent Docker volume used to store Jenkins data.--restart unless-stopped: Automatically restarts Jenkins after a container failure or server restart unless the container was explicitly stopped.
Verify that the container is running:
docker ps
You can also check the Jenkins container logs:
docker logs jenkins
Step 3: Configure the Linux Server Firewall
If a firewall is enabled on the Linux server, the required ports must also be allowed at the operating-system level.
For UFW on Ubuntu or Debian
sudo ufw allow 8080/tcp
sudo ufw allow 50000/tcp
sudo ufw reload
Verify the rules:
sudo ufw status
For Firewalld on RHEL, CentOS, or Fedora
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --permanent --add-port=50000/tcp
sudo firewall-cmd --reload
Verify the configuration:
sudo firewall-cmd --list-ports
If Jenkins agent connections do not use port 50000 in your configuration, you do not need to expose that port.
Step 4: Configure the Azure Network Security Group
Azure Network Security Groups (NSGs) control inbound and outbound network traffic associated with Azure resources.
To make Jenkins accessible externally, the NSG associated with the VM or its subnet must allow the required inbound traffic.
Join the conversation! Your thoughts help the community grow.