Configure HTTPD on Docker Containers

apache.png

In this blog, we will see how to configure an HTTPD web server on the docker containers.
HTTPD is the Apache HyperText Transfer Protocol (HTTP) server program. It is designed to be run as a standalone daemon process.

Pre-requisites:

Docker should be installed.

Step 1: Create the Docker container

We will use the centos image for creating the docker container. The version that we will use is the centos:latest.

Use the following command to create the Docker container

docker run -it --name myHttpd centos:latest bash

Let's see what this command does.
The -it options are used to get the interactive terminal so that we can run the command in the docker container.
The --name option is used to give the name to the docker container.
Next, we will give the image name. In this case, the image is centos:latest.
At last, we will tell the command to run. In this case, the command is bash.

Docker runs only one command when it creates the container and then stops the container after running that command. As we want to get the terminal so that we can run commands to configure the HTTPD web server on the docker container.
The bash command is the command that will give us the bash shell and this command will run forever if we don't exit from the container.

t4.png

Step 2: Install HTTPD software

Now, we are inside the docker container and we can execute the commands.

For installing the HTTPD software, we will run the following command

yum install httpd

t5.png

t6.png

Step 3: Start the HTTPD service

We can start the HTTPD service in multiple ways, but the docker container doesn't support systemctl command.
So, we will start the HTTPD service using the httpd.service file directly.

t10.png

$ /usr/sbin/httpd