Exercise Description:

In this exercise, you will learn how to create a container image using a dockerfile.  Dockerfile is the file in which you can write instructions and that instruction will execute while creating the image. In dockerfile, many instructions are there but in this exercise, you will learn how to create a simple httpd using podman.

Quick example:

Let’s create a simple httpd container image using a dockerfile. As you know container image is important to create a container. Your container image will hold the all necessary information about your application. So step by step you have to create and execute an instruction in dockerfile. Each instruction will create a new image layer inside a container image.

step1: Create a file named dockerfile and add very first instruction is FROM.  FROM instruction used to specify the valid docker image name. So specified docker image will be downloaded from docker hub registry if it is not exists locally. Here you will use the centos image as a base image in the httpd image. The next instruction is MAINTAINER. It is used to specify about the author who create this new image.

step2: Now next step is installing a package in an image using RUN instruction. This instruction is used to execute any command inside an image.

step3:In this step, you will add index.html file inside a default apache directory. For that you can use ADD instruction. This instruction will copy a file from your local machine to inside your image

step4:Now you have to  expose your httpd to 80 port. EXPOSE instruction will instruct Container to listen on port 80 but the port will not available to outside. 

step5: In last step you have to instruct the container to run apache service the foreground after container is started.  For that you have to use CMD instruction.

If you dont use this argument the server will start and then it will stop. 

Overview of dockerfile is:

FROM docker.io/centos

MAINTAINER Administrator

RUN yum install -y httpd

ADD index.html /var/www/html


CMD [“/usr/sbin/httpd”, “-D”, “FOREGROUND”]

Now Create a dockerfile using: 

$ podman build -t dockerfile .

This command will create an image in your local machine. 

This is the way, you can create your own container image using dockerfile. 


Build an image of name “sampleimage” with packages vim on base image alpine:3.4