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

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

Manage Batch Jobs with AWS Batch

Software Quality Gifts

Authenticate Spring boot API with AWS Cognito

Monitoring Plus System Metadata

Rancher deployed Kubernetes on Oracle Cloud Infrastructure

“Why can’t we plan Sprints accurately with velocity?”

Three cups of coffee on a stool

What I’m looking for with behavioral questions in a software engineer interview

Change the Focal Point of Your Backlog to Unlock Better Commitment and Productivity

A man holds up a camera lens through which a beautiful landscape can be seen.

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

Send AT Commands to Smartphones Serial Modem With Python

Docker in a Nutshell

ROS Communication Via Docker Containers

Docker/Container Introduction