How to create a custom Docker image with centos, JDK8 and Maven in the case of Jenkins integration with a Docker slave


Step 1: Setup your environment

Step 2: Create a Dockerfile

FROM centos:latestLABEL Tchamie Edmond <>RUN  yum update -y && yum -qy install git && yum -qy install net-tools 
  • FROM centos:latest: This is the starting point for your Dockerfile. Every Dockerfile typically starts with a FROM line. This FROM command receives as argument a basic existent docker image that we will use to build our layers on top of. The base image passed as argument is centos:latest. This image contains a jdk version 8 already installed. The latest version means we’ll download the latest version of centos available in docker hub.
  • LABEL Tchamie Edmond <>: LABEL command defines the maintainer of the image, in case you want to contact him/her for any reason.
  • The RUN command executes instructions at build time. It means that you can use it to configure the image by adding application, installing packages, defining security rules… In our case, we use the yum package management utility (included within centos distributions) to install some tools we need to have available when running a container based on our image, like curl, tar, net-tools and git…

Step 3: Adding openssh-server, jdk, maven to our Dockerfile

Step 4: Adding jenkins user to our Dockerfile

Step 5: Building the image

$ docker image build -t jenkins-slave-maven-jdk:latest .#Beware that the "point (.)" at the end of cmd means current folder of your Dockerfile
Successfully tagged jenkins-slave-maven-jdk:latest
$ docker container run -d -it jenkins-slave-maven-jdk bash

Step 6: Pushing the image on Dockerhub

  • Navigate to Docker Hub and create a free account if you haven’t already.
  • Log in to the Docker registry account by typing docker login on your terminal and providing your credentials.
$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to to create one.
  • Tag the image with your username
$ docker tag jenkins-slave-maven-jdk  tcdocker2021/jenkins-slave-maven-jdk
  • Push your image to the Docker Hub registry:
$ docker push tcdocker2021/jenkins-slave-maven-jdk





Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Edmond Tchamie

Edmond Tchamie


3rd Year CSE Student, Technology Passionate(Docker, AWS, K8s,Rhel Linux,...), Aspiring Security Expert😁