Create a Docker Image Using a Dockerfile

This blog post will show you how to create a Docker image using a Dokckerfile running on a Linux CentOS host.


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

Using a Dockerfile, we can 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 | tee
RUN yum install -y powershell /etc/yum.repos.d/microsoft.repo
CMD ["pwsh"]

The image is based on the latest CentOS docker image and we 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

Categorized as Docker

Leave a comment

Your email address will not be published. Required fields are marked *

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