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.
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
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.
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.
Agent-Based Installation The Agent-based installation method provides the flexibility to boot your on-premise servers in…
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…
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.…
OpenShift supports multiple deployment methods, including UPI, IPI, and the Assisted Installer. Previously, if you…
Oracle Linux Virtualization Manager based on oVirt, which is a free, open-source virtualization solution. Engine…
You may refer to my earlier post – how to deploy Azure locally on vSphere.…
View Comments