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

Installing OpenShift 4.21 in an air-gapped on-premises/BareMetal environment using Agent-based deployment

Agent-Based Installation The Agent-based installation method provides the flexibility to boot your on-premise servers in…

2 months ago

OpenShift Virtualization Configuration, Secondary VM Network Setup, and Live Migration configuration

You can check the earlier post regarding cluster setup and ODF setup https://kdinesh.in/deployment-of-openshift-4-20-with-using-the-assistant-installer/ https://kdinesh.in/openshiftodf/ Login…

3 months ago

OpenShift Install OpenShift Data Foundation (ODF) using Multus network Isolation

You can check the earlier post regarding cluster setup https://kdinesh.in/deployment-of-openshift-4-20-with-using-the-assistant-installer/ 1.Install nm state operator 2.…

3 months ago

Deployment of OpenShift 4.20 with using the Assistant Installer

OpenShift supports multiple deployment methods, including UPI, IPI, and the Assisted Installer. Previously, if you…

3 months ago

Oracle Linux Virtualization Manager (OLVM) Deployment and Configuration

Oracle Linux Virtualization Manager based on oVirt, which is a free, open-source virtualization solution. Engine…

4 months ago

Azure Kubernetes Service(AKS) Deploy on Azure Local(Azure HCi)

You may refer to my earlier post – how to deploy Azure locally on vSphere.…

4 months ago