Configure httpd server in docker container

Shobhit Singh Pal
3 min readMar 8, 2022

Using AWS instance to do the practical. As in AWS amazon linux 2 yum is configured for the docker so we don’t need to configure for the docker.

Install the docker

yum install docker

Start the docker service

systemctl start docker

Launching centos container

docker run -it --name <container:name> -p 8080:80 centos:8
# here we are exposing the port 80 of the container on the 8080 port of the host machine.

if you expectedly from the container, run the following command to get the container shell.

docker exec -it <container:name> <shell:name>
For Example
docker run -it os /bin/bash

Installing the net-tools

Running ifconfig command

As in centos the ifconfig command is not available that’s why installing it through its software net-tools.

We are getting the appstream related error which is related to yum repos. To resolve it run the following commands

cd /etc/yum.repos.d/sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*yum update -y

Install the httpd

yum install httpd

Starting the httpd service

systemctl start httpd

You will get the following error:

The reason behind is broad but trying to putting in following points

  • Normally when you run a container you aren’t running an init system. systemctl is a process that communicates with systemd over dbus. If you aren’t running dbus or systemd, I would expect systemctl to fail.
  • systemctl is used to examine and control the state of “systemd” system and service manager.
  • systemd is system and service manager for Unix like operating systems.

Instead of resolving the above error we will bypass and will directly run the httpd daemon.

Ignore this error. Our focus is to launch the httpd server in container and httpd server is started on the backend.

So go to your browser, type the machine ip and 8080 port:

httpd running

Done with task.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Shobhit Singh Pal
Shobhit Singh Pal

No responses yet

Write a response