How to Configure Apache Webserver “httpd” in Docker Container

Gayathri Priya
5 min readMar 14, 2021

What is Ansible?

Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code.

there are some of the terminology used in Ansible:

  • Controller Node: Machine where Ansible is installed.
  • Managed Node: Managed nodes are also sometimes called hosts.
  • Inventory: Information regarding servers to be managed
  • Playbook: Automation is defined using tasks defined in YAML format
  • Task: Procedure to be executed
  • Module: Predefined commands executed directly on remote hosts.

What is Docker?

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications.

In this we do the following tasks:

  • Configure Docker
  • Start and enable Docker services
  • Pull the httpd server image from the Docker Hub
  • Run the httpd container and expose it to the public
  • Copy the html code in /var/www/html directory and start the
    Web-Server.

Step 1: Install Docker-CE software on Redhat 8

We directly cannot install the docker-ce software on Redhat 8. To install the docker-ce software on Redhat 8 first we have to create the repo for the software.

Now let’s list the repolist, It will show how many software have.

Step 2: Install the docker-ce software on Redhat 8

In this step, we will install the docker-ce software. To install we will use yum command.

yum install docker-ce — nobest -y

Now we can check the version of the Docker software.

docker — version

Step 3: Start the status of Docker

In this step, I will start the docker status with the systemctl command. Also, we will check the docker status.

systemctl start docker

systemctl start docker

Now enable the docker service so that the docker service will be running after the system restarts. To enable the service we have to use the enable option.

systemctl enable docker

Here we can see that the docker service is enabled.

Step 4: Pull any Docker Image from the docker repository

In this step, I am going to pull the centos image from the docker repository. Let me first show how many docker images are available.

To list the docker images available we have to use the image command.

docker images

We can see that there is no docker image available, now let’s download the centos image.

docker pull centos

Now we can check that the centos image is downloaded or not.

We can see that the centos image with the latest tag is downloaded.

Step 5: Launch the docker container with centos image

In this step, I will launch a docker container with a centos image.

docker run -it — name webos centos

We can check the container is running or not, to check we can use the docker ps command.

docker ps

By default, the centos image that we have don’t contain ifconfig command. So we can install the software which provides ifconfig command.

net-tools is the software that provides the ifconfig command. So, we can install this software with the yum command.

yum install net-tools -y

Now we can check the IP of the container.

Now we can check the IP of the container.

Step 6: Install apache HTTPd software

To install the httpd software we can use the yum command.

yum install httpd -y

Step 7: Put the web page inside /var/www/html directory

By default httpd software reads the HTML file from /var/www/html directory. So we have to put the HTML file inside the /var/www/html directory.

Here i have created aditya.html file inside /var/www/html directory.

Step 8: Start the httpd service

Now, at last, we have to start the service of httpd service. By default, systemctl command is not present. So we can use /usr/sbin/httpd file because systemctl internally loads this file to start the service.

Now we can access the web page from the browser.

We can see that we can easily access the web page which is there on the docker container.

Thanks for reading!

--

--