Publish Jenkins Docker agent to Docker Hub Public Registry

Jenkins is a software development-related tool that helps improve efficiency by automating repetitive tasks that can lead to errors if performed manually. It helps in easing the software development process through various integrated tools.

Docker Hub Public Registry

Docker Hub Public Registry contains Docker images that are open access. The collection of these containers can be used and run by anyone.

Docker agent

A Docker agent is a worker node that performs various tasks as instructed by a control system central to it. In the case of Docker, these agents will be Docker containers. Creating these agents is a dynamic process; each container has its set of dependencies and requirements according to the task it is created for.

Following is a step-by-step guide on how to publish Jenkins Docker agent to the Docker Hub registry:

Determine Docker agent configurations

Create a Dockerfile that contains the following:

  1. The base image for Jenkins

  2. Required dependencies

  3. Required configurations

FROM jenkins/inbound-agent:4.10-1
# Replace the <your-package-list> place holder with required packages
RUN apt-get update && apt-get install -y <your-package-list>
# Replace config-file with the name of the file you want to include
# Replace /path/in/container with the path where you want to place the file in the container
COPY config-file /path/in/container

Explanation

Line 1: Base image for Jenkins

  • FROM: This keyword indicates that you’re starting with a base image.

  • jenkins/inbound-agent: This indicates the name of the base image. You will use the official Jenkins agent image.

  • 4.10-1: This specifies the tag or version of the base image you’re using.

This line instructs Docker to use the jenkins/inbound-agent image with the 4.10-1 version as the initial point to build upon in order to form a custom Jenkins agent image.

Line 3: List of packages

You can then add more instructions to this Dockerfile to customize the image as needed for your specific use case, such as installing additional dependencies.

Line 6: Required configurations

Further customization can be carried out by configuring settings or adding your application code.

Build the Docker image

Before this step, ensure you have access to a running Docker engine. If you are using Docker Desktop, ensure that it is running.

Open the terminal on your device, navigate to the folder containing the Dockerfile, and use the following command to build the Docker image for the Jenkins Docker agent:

#Replace your-username with your username on Docker Hub
#Replace tag-name with the version or any tag you want to give to your image
docker build -t your-username/jenkins-agent:tag-name .
Build Docker image

Test the Docker image

Once the image is built, you should run a container based on the image to ensure that it is performing as desired.

#Replace your-username with your username on Docker Hub
#Replace tag-name with the version or any tag you gve to your image
docker run -it --rm your-username/jenkins-agent:tag-name
Test Docker image

Expected output

Jenkins agent running

Docker Hub signup/login

If you do not have a Docker Hub account already, you can sign up for one.

If you have an account, use the following command to log in to your Docker Hub account:

docker login
Login to Docker Hub

This will prompt you to enter your Docker Hub account credentials, and just like that, you will be logged in.

Push the image on the Docker Hub

#Replace your-username with your username on Docker Hub
#Replace tag-name with the version or any tag you gve to your image
docker push your-username/jenkins-agent:tag-name
Push the image on Docker Hub

Verify on the Docker Hub

Log in using your account credentials and visit your profile. By visiting your profile and searching for the pushed image, you can ensure that the image has been successfully pushed.

The guide helps you build a basic image and push it to the Docker Hub. However, depending on your use case, you will need to customize the Docker image according to the requirements at hand.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved