Create Our Own Docker Image

Custom Docker

In this practical, we are going to build a docker image, ship the image into a docker hub, and run the docker container.

Docker build, ship and run

Docker provides a simple way to configure any docker image and create your own custom image. We can create Docker images in two ways using the commit command and Dockerfile.

Create Image Using commit command:

The easiest way to begin is to create a container from a pre-existing image, make your changes, then save this container as an image. For this tutorial, we will create a container from the official CentOS image, then save this new container as an image using docker commit.

The official CentOS 7 image is named centos. You can download it from the Docker registry with the command:

docker pull centos

Begin by launching a container named website from the centos image with the command:

sudo docker run -it --name website centos bash

Once you are at the command prompt in the new container, install the httpd module with the command:

yum -y install httpd

then go inside the /var/www/html/index.html file

vi  /var/www/html/index.html

Write an HTML code

HTML code

After saving this file, now we need to BUILD an Image Using Commit

Create Image

Display Image

Show Image

After Building now needs to PUSH Image into Docker HUB before that needs to login to Docker with Docker Name and password then push.

Now you can see Docker Image is pushed to hub

There are significant downsides to the commit approach:

You can’t reproduce the image.

You can’t change the base image.

Even if we try to use this image in the automation world it won’t support like KUBERENETES

Let me show one example, below example we can’t launch container.

Therefore always better to use the Dockerfile concept to create our own Image, now let us BUILD and PUSH(SHIP) an Image.

STEP1: Create a Directory with any name

STEP2: Create a file with Name Dockerfile name should be the same

STEP3: Write a code in Dockerfile


STEP4: Now let's Build an Image using the build command

Build Image

Show Image

Show image

Launch new container with the name myweb

Run Container

Check an Apache server whether it's working or not, Now our image is successfully working.

I tried my best to explain, Thank you for reading….

ARTH-School of technology, BCA graduate

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The hidden costs of serverless

Building a GraphQL API with Magnolia CMS

How to Mount a Directory Inside a Docker Container

Automatic Kubernetes deployment with Gaia and HashiCorp Vault

TiDB Dashboard: Easier Troubleshooting for Distributed Databases

Practical Monitoring with Prometheus & Grafana (Part III)

How to quickly run a basic security audit against docker & secure the host…

Java Interview Series: Security

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
Vinodha kumara

Vinodha kumara

ARTH-School of technology, BCA graduate

More from Medium

The Future of Programming? Python Game Automation with Image Recognition

Heroku Deploy using CLI

Build and Deploy Python Errbot & ChatOps Slack Integration

How to find the screen coordinates of a web element