Install Docker and Jenkins on a dedicated IP system by first updating your package manager, installing prerequisites like apt-transport-https or yum-utils, adding the official GPG key and repository, then enabling the service. Configure Jenkins with a reverse proxy for secure access over HTTPS, ensuring your firewall allows traffic on port 80 and 443 while keeping the internal Jenkins port isolated.
Preparing the Operating System Environment
Before installing any containerization or continuous integration tools, you must ensure your operating system is up to date and has the necessary dependencies. The specific commands vary depending on whether your dedicated IP server runs a Debian-based distribution (like Ubuntu) or a Red Hat-based one (like CentOS or Rocky Linux). It is crucial to identify your OS early because mixing package managers will cause installation failures. For Debian-based systems, start by refreshing your local package index. This ensures that when you request new software, you are pulling from the most recent sources available in your repositories. Run the following command to update the cache:sudo apt update
sudo apt upgrade -y
Next, install the prerequisite packages that allow APT to use repositories over HTTPS. These tools are essential for securely downloading Docker and Jenkins binaries from their official channels. You should also install common utilities like curl and ca-certificates, which are often required for verifying software signatures during the setup process.
sudo apt install -y apt-transport-https ca-certificates curl gnupg lsb-release
If you are using a Red Hat-based system, the process begins similarly but uses different package management tools. Update your system packages using yum or dnf, depending on your specific version. Then, add the necessary repository configuration files. Unlike Debian, RHEL systems often require you to explicitly enable certain repositories before they become accessible.
sudo yum check-update
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
Identifying your platform correctly prevents errors later in the tutorial. If you are unsure, you can check your distribution by running cat /etc/os-release. This command outputs detailed information about your Linux version, helping you confirm which set of instructions applies to your dedicated IP environment.
Installing Docker Container Runtime
Docker is the foundation for running modern development tools like Jenkins in isolated environments. Adding the official Docker repository ensures you get security patches and feature updates directly from the maintainers rather than waiting for your OS distributor to package them. First, download the official GPG key for Docker. This key verifies that the packages you install have not been tampered with. Use curl to fetch the key and store it in the trusted keys directory.curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
For Red Hat systems, the command differs slightly due to the different key storage location. Ensure you follow the documentation specific to your variant. Once the key is added, create a repository file that points to the correct mirror for your architecture. This step tells your package manager where to find Docker Engine packages.
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
After configuring the repository, update the package index again to recognize the new source. Install the latest version of Docker Engine, CLI, and containerd. On some systems, you may need to specify the exact version string if you want to pin a specific release, but generally, installing the latest meta-package is sufficient for learning environments.
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io
Verify the installation by checking the status of the Docker service. It should be active and running. If it is not, check the logs using journalctl -u docker.service to diagnose startup issues related to permissions or network conflicts.
Deploying Jenkins via Docker Compose
Rather than installing Jenkins directly on the host OS, using Docker provides better isolation and easier cleanup. Create a project directory and define adocker-compose.yml file. This file specifies the services, networks, and volumes required for Jenkins to function correctly.
version: '3.8'
services:
jenkins:
image: jenkins/jenkins:lts
restart: always
user: root
ports:
- "8080:8080"
volumes:
- jenkins_home:/var/jenkins_home
volumes:
jenkins_home:
This configuration maps port 8080 from the container to the host. Since you have a dedicated IP, you can access this port directly from outside your local network. However, exposing Jenkins directly without encryption is risky. It is recommended to place a reverse proxy in front of Jenkins to handle SSL termination.
You can refer to our guide on Setting up Let's Encrypt SSL with Caddy and Serving Multiple Services using Docker Containers on Vault Warden to learn how to configure Nginx or Caddy as a reverse proxy. This adds a layer of security by encrypting traffic between your browser and the server.
Start the stack using the compose command. This downloads the images and creates the containers. Check the logs to see if Jenkins initializes correctly. The first time you access the web interface, you will need to unlock Jenkins using an initial admin password stored in the volume.
docker-compose up -d
docker-compose logs -f jenkins
Configuring Firewall and Network Access
With a dedicated IP, your server is visible to the internet. You must restrict access to only necessary ports. Typically, you need HTTP (80) and HTTPS (443) open for web traffic. If you are not using a reverse proxy immediately, you might expose 8080 temporarily for setup, but close it afterward. Use UFW (Uncomplicated Firewall) on Ubuntu or firewalld on CentOS to manage rules. Allow SSH access so you do not lock yourself out. Then, allow HTTP and HTTPS.sudo ufw allow OpenSSH
sudo ufw allow http
sudo ufw allow https
sudo ufw enable
If you choose to keep Jenkins on port 8080 for direct access, add a rule for that port as well. However, remember that Jenkins generates random passwords and stores sensitive data. Always pair direct access with strong authentication or move to a reverse proxy setup. For more insights on securing internal services, consider reading Setting Up an Internal Email Server (Docker) for Application Home Lab Use, which covers similar security principles for other services.
Frequently Asked Questions
How do I reset the Jenkins admin password?
If you lose the initial password, stop the Jenkins container and delete the secret files inside the mounted volume. Specifically, remove /var/jenkins_home/secrets/initialAdminPassword. Restart the container, and Jenkins will generate a new password upon next launch.
Can I run Jenkins without Docker on my dedicated IP?
Yes, you can install Jenkins directly using apt or yum, but this mixes application dependencies with your OS libraries. Docker isolates these dependencies, making upgrades safer and preventing conflicts with other software installed on the same machine.
Why is my Jenkins site showing a connection refused error?
This usually means the Docker container is not running or the port mapping is incorrect. Check the container status with docker ps. If it is running, verify that your firewall is not blocking port 8080 or that no other service is already using that port on the host.
How do I back up my Jenkins data?
Jenkins stores all jobs, configurations, and plugins in the jenkins_home volume. To back up, simply copy the contents of this volume directory to another location. Restoring involves pointing the Docker volume to this backup directory when starting the container.
Is it safe to expose Jenkins directly to the internet?
No, it is not safe without additional security measures. Direct exposure leaves you vulnerable to unauthorized access if credentials are weak. Using a reverse proxy with SSL and basic authentication or integrating with LDAP/SSO is strongly recommended for production-grade setups.