Create Our Own Docker Image

Vinodha kumara
3 min readJan 24, 2021

--

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

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….

--

--

Vinodha kumara

DevSecOps, MLOps, Cloud Computing, DE, ML, DL, Programmer, Blogger, Volunteer