Skip to content
Related Articles

Related Articles

Improve Article
How to create your own Docker Customised Image ?
  • Difficulty Level : Easy
  • Last Updated : 16 Jul, 2020

Docker is an open-source container management service and one of the most popular tools of DevOps which is being popular among the deployment team. Docker is mostly used in Agile-based projects which require continuous delivery of the software. The founder, Chief Technical Officer, and Chief Architect Officer of the Docker Open source project is Soloman Hykes. It was launched in 2013 by Dotcloud, since then it is the world’s leading software container platform. For more details about the containerization using docker and it’s internal architecture click here.

In this article, we will see how we can create our own customized Docker images and how we can push it to the docker hub profile. It is good practise to push your images to docker hub profile as you don’t have to create it again and you can pull those images in your system as well as in cloud with all your work saved in it.

Creating docker images is not a tedious task. We can create a docker image easily with few commands. There are two ways of creating a docker image depending upon the purpose for which you want to create the image. The first method is using commit command and another method is by using Dockerfile concept. To read more details about the components of docker ie, Docker images and Docker File click here.

Now let’s start creating our own customized docker image using the commit command. Before going with our own docker image we should first set up and configure docker in our operating system. To learn more about how to setup docker you can refer to this article. After successful installation let’s learn some of the docker commands which we will be using.

Commands Required

The first command is pull command. This command will download/pull the complete operating system within seconds depending upon your internet connectivity. The syntax is like, docker pull image_name. Here I am pulling alex43/ubuntu-with-git:v1.0 which is my own customized image.



docker pull alex43/ubuntu-with-git:v1.0

The second command is run command which we will use to run the pulled image. This command will launch my image and we will get an interactive shell/terminal of that image. The syntax is like, -it for an interactive terminal, –name to give reference name for my image launched and then my image_name.

docker run -it --name myos alex43/ubuntu-with-git:v1.0

The third command and the most important command for creating our own image is commit command. By using this command we can simply create our own image with the packages which we want from the existing image. The syntax is like, docker commit Nameof_RunningImage your_own_name:tag.

docker commit myos ubuntu-basicbundle:v1.0

The fourth command is tag command. By using this command we need to rename our image with syntax username/image-name:tag. Before executing this command you need to create an account on the Docker hub and you have to give the same username which you have given in the docker hub profile.

docker tag alex43/ubuntu-with-git:v1.0 alex43/ubuntu-basicbundle:v1.0

The fifth command is login command. By using this command we will logged in to the docker hub account through our terminal and it is required to upload our docker image to the docker hub profile.

docker login --username alex43 --password your_passwd

The fifth command is push command. By using this command we can upload our own created docker image to the docker hub profile and can use it anywhere from our local system to cloud by pulling it.

docker push alex43/ubuntu-basicbundle:v1.0

So these were the few commands with the concept which we will be using in this tutorial and I will be uploading one fresh image so that you guys can understand it in a better way.

My Own Image

Now we will create our own image from existing alex43/ubuntu-with-git:v1.0 image and we will customise it with our needs and we will upload it.

Step 1: The very first step is to pull the image as I have shown in the upper commands. Use the command and pull the image into your system.
docker pull alex43/ubuntu-with-git:v1.0



Step 2: Launch that image so that we can customize it as per our needs. In the below picture you can see that at 1st we were not having vim editor in our image so it was giving error of command not found. Then I installed vim in our system by using apt-get install vim command.

In the below image you can see that after installing vim editor when I opened abhi.txt with vim editor it didn’t gave any error and I was able to write content in that. You can also see the content using cat command which we already have in alex43/ubuntu-with-git:v1.0 image.

So it was only the step that you need to understand and apply your own concepts. You can create lots of more useful docker images to solve some industry use cases like launching a WordPress blogging site using a docker image, creating your own MySQL database image, etc. It is the basic concept which you need to understand and apply as per your needs.

Step 3: Come out of the image by pressing ctrl+p+q and commit the modified image as I have explained in the above command.
Step 4: Create an account at docker hub and change the name of the image with proper syntax as explained above.
Step 5: Log in into docker hub profile from terminal using docker login command as explaied above.
Step 6: The final task is to upload the image using push command to docker hub profile as explained above.

For step-3, step-5, and step-6 you can see the image below. Pushing your image might take some time depending upon the size of the image and the internet speed of your system. In the image, you can see I have used the commands which I explained above and it successfully uploaded my image at my docker hub profile.

So in this way we can create our own docker image and push it to docker hub just by using few commands.

My Personal Notes arrow_drop_up
Recommended Articles
Page :