VMware

Creating Own Container Image and Pushing Container Image to local Private Registry -Harbor, and Deploying image on Tanzu Kubernetes Cluster

Generally, Container Images are provided by Application Vendors. Sometimes, we must build our container images, EX: hosting any website …etc.

The document below will explain how container images(example image – httpd) are created and how we use images.

For Creating Container Images, first, we must install docker on any supported operating system.

You can check the following doc for installing the Docker – https://docs.docker.com/engine/install/

In my Env on CentOS 8 Stream, Docker is installed.

Next, create one directory for creating Docker image files. (optional)

Switch to the newly created directory and create a .dockerignore file.

.dockerignore files play an important role in creating more compact, faster-running containers – by providing a way to prevent sensitive or unnecessary files and directories from making their way into your image builds. Your .dockerignore file should be located in the root directory, known as the build context, from which you intend to develop your image.

You can check the following link for more info about why .dockerignore – https://codefresh.io/blog/not-ignore-dockerignore-2/

Next, create an actual Docker image file – Dockerfile and prepare Dockerfile based on the requirement.

In the below example -, I am creating an httpd docker image.

Dockerfile contained a Total of nine lines.

  1. From – instruction will pull the RedHat 8 version Image from the Repository.

Every OS vendor will maintain different versions & type OS container images. (OS image means not like standard OS image. It will contain only minimal packages)

You can find different Red hat-certified container images in RedHat Portal – https://catalog.redhat.com/software/containers/explore

Also, you can find all kinds of OS and other container images in Docker Hub

  1. Maintainer – Optional
  2. RUN – Updating the Redhat 8 OS, installing the httpd software, and adding “virgin media cloud team” to the index.html file; the last two commands in RUN clear unnecessary files and cache.

Why all commands in single Run command instead of 5 Run commands – A Docker image takes up more space with every layer you add. Therefore, the more layers you have, the more space the image requires.

  1. Expose – We expose port 80 as the httpd service listens on port 80.
  2. CMD – We last run the httpd server using CMD instruction when the Docker image launched.

Docker File Commands Overview

Command

Purpose

FROM

To specify the parent image – ubuntu, Centos, Redhat …etc.

WORKDIR

To set the working directory for any commands that follow in the Dockerfile.

RUN

To install any applications and packages required for your container.

COPY

To copy over files or directories from a specific location.

ADD

As COPY, but can also handle remote URLs and unpack compressed files.

ENTRYPOINT

A command that will always be executed when the container starts. If not specified, the default is /bin/sh -c

CMD

Arguments passed to the entry point. If ENTRYPOINT is not set (defaults to /bin/sh -c), the CMD will be the commands the container executes.

EXPOSE

To define which port through which to access your container application.

LABEL

To add metadata to the image.

Next, Build Container Image using DockerFile.

Docker build -t tagname .

It may take a few minutes to build an image based on the Dockerfile.

Once the build is completed successfully, run the ‘docker images’ command to check the images.

Run container image on docker test image is working based on the docker file instructions.

You can check screenshot container image is working.

Next, Push the Container image to the Local private Repository Harbor.

In My env Harbor already deployed. In Harbor, create a lab project.

You can check my previous post – how to deploy Harbor – https://kdinesh.in/harbor/

Run command – docker login harbor URL. Enter your Username and password. (only First-time login Docker will ask for a harbor username and password)

Tag image and push Image to Harbor project. (assigned tag https, pushed the image to lab project)

You can check on Harbor GUI. The HTTPS repo is created in the Lab project, and the image is available in the HTTP repo.

Next, Deploy the Httpd image on the Tanzu Kubernetes cluster.

Create deployment yaml file. In file-specific local harbor repo image address (harbor. kdinesh.in/lab/https:1.0 – harbor.kdinesh.in – Harbor URL, Lab – Project name in harbor, https is image name, and 1.0 is the tag )

Run deployment yaml file.

Kubectl apply -f “yaml file.”

After deployment, check whether the pod is running or not.

You can also check deployment events.

Kubectl describe podname -n namespace

You can see the below screenshot image is pulled from the local harbor repository.

In the yaml file, the specified service type as load balancer – AVI is already integrated with Cluster. So, AVI LB issued LB VIP IP.

You can use the browser Load Balancer IP.

Dineshreddy Kayithi

Rooted in a solid academic foundation with a Bachelor's Degree in Information Technology, my career has been deeply entrenched in designing, deploying, and managing enterprise-grade infrastructure across virtualization, cloud-native, and containerized environments. Industry certifications from VMware, AWS, Microsoft, and Kubernetes validate my hands-on expertise in architecting scalable, resilient systems spanning hypervisors, public/hybrid cloud platforms, and container orchestration frameworks. I'm driven by a relentless pursuit of emerging technologies — translating them into production-ready solutions that solve complex operational challenges.

View Comments

Share
Published by
Dineshreddy Kayithi

Recent Posts

Canary Deployments on OpenShift with GitOps: A Practical Walkthrough

Shipping a new version of an application is always a small act of faith. Even…

2 weeks ago

OpenShift VM Backup and Restore

The following steps demonstrate how to back up and restore an OpenShift virtual machine using…

2 months ago

Red Hat OpenShift VM Micro-segmentation Using MultiNetworkPolicy

OpenShift Virtualization allows virtual machines (VMs) to run natively on Kubernetes alongside container workloads. Using…

4 months ago

Red Hat OpenStack Services on OpenShift (RHOSO)

Red Hat OpenStack Services on OpenShift (RHOSO) provides the foundation to build a private or public…

4 months ago

Kubernetes Cluster Deployment

Kubernetes (often shortened to “K8s”) is an open-source system for automating the deployment, scaling, and…

4 months ago

Ceph cluster on a single machine

Ceph is an open-source, distributed storage platform that provides object, block, and file storage in…

4 months ago