Create a Docker Image Using a Dockerfile Linux CentOS

In this blog post, I will show you how to create a Docker image using a Dokckerfile running on a Linux CentOS host.

Dockerfile

On a high level, a Dokcerfile is a runbook with a set of instructions that together build a Docker image.

Using a Dockerfile we streamline the entire process of building images.

Create Folder

The first step in creating a folder where we will put our Dockerfile in.

In my case, I will create a folder called build01

Create a Dockerfile

Next, I will create a Dockerfile using the following command:

nano dockerfile

Note: The file can be start with or without a capital d.

Below you can see the actual Dockerfile content.

FROM centos:latest
RUN curl https://packages.microsoft.com/config/rhel/7/prod.repo | tee /etc/yum.repos.d/microsoft.repo
RUN yum install -y powershell
CMD ["pwsh"]

The image is based on the latest CentOS docker image and will install PowerShell 7.

Build Image

To build the image, I will run the following command and at the end, I will have an image called powershell-v1.

docker build -t powershell-v1 .

When I run the docker images command I will see it listed.

Run image

To deploy my image, I will run the following command:

docker container run -it powershell-v1

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.