How To Create Apache Web Server By Docker On Rocky Linux 8.6

To Create Apache Web Server By Docker On Rocky Linux 8.6

Introduction:

Docker is an open-source software platform for creating, deploying, and managing virtualized application containers. Reverse proxy servers are generally behind a firewall in private networks, and they forward client requests to the relevant backend servers.

Procedure:

Step 1: Check the OS version by using the below command

[root@linuxhelp ~]# cat /etc/os-release 
NAME="Rocky Linux"
VERSION="8.6 (Green Obsidian)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="8.6"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Rocky Linux 8.6 (Green Obsidian)"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:rocky:rocky:8:GA"
HOME_URL="https://rockylinux.org/"
BUG_REPORT_URL="https://bugs.rockylinux.org/"
ROCKY_SUPPORT_PRODUCT="Rocky Linux"
ROCKY_SUPPORT_PRODUCT_VERSION="8"
REDHAT_SUPPORT_PRODUCT="Rocky Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="8"

Step 2: Mapping the location /home/user/website/ location by using the below command

[root@linuxhelp ~]# docker run -dit --name webhost -p 8080:80 -v /home/user/website/:/usr/local/apache2/htdocs/ httpd:2.4
Unable to find image 'httpd:2.4' locally
2.4: Pulling from library/httpd
461246efe0a7: Pull complete 
d6bc17b4451a: Pull complete 
72dcd3e40e39: Pull complete 
c332ae8365a7: Pull complete 
97f4b88189d8: Pull complete 
Digest: sha256:75d370e19ec2a456b6c80110fe30694ffcd98fc85151a578e14334a51eb94578
Status: Downloaded newer image for httpd:2.4
2e60fb41d6337e6dd476f63e8b3c5480d2fe9396b952a6d1375499357bc97c31

Step 3: View the docker image by using the below command

[root@linuxhelp ~]# docker ps
CONTAINER ID   IMAGE       COMMAND              CREATED          STATUS          PORTS                                   NAMES
2e60fb41d633   httpd:2.4   "httpd-foreground"   13 seconds ago   Up 11 seconds   0.0.0.0:8080->80/tcp, :::8080->80/tcp   webhost

Step 4: Now create a simple web page named by index.html inside the /home/user/website directory by using the below command

[root@linuxhelp ~]# vim /home/user/website/index.html
<!DOCTYPE html>
<html lang="en">
<body>
    <h1>Welcome to linuxhelp</h1>
</body>
</html>

Step 5: Go to browser and ping Server-IP:8080 as shown in the below image

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to create Apache Web Server by Docker on Rocky Linux 8.6. Your feedback is much welcome.

FAQ
Q
How to Map the container port to the host port?
A
To Map the container port to the host port use the flag docker run -p with
Q
What is the purpose of Flag -t on docker run Command?
A
The purpose of Flag -t on docker run Command is to Allocate a pseudo-TTY
Q
How to execute a command on Container?
A
To execute a command on Container by "docker exec "
Q
How to enable the Nginx Server Block?
A
To enable the Nginx Server Block by "ls -s /etc/nginx/sites-available /etc/nginx/sites-enabled"
Q
What is a Reverse proxy server?
A
A reverse proxy server is a type of proxy server that typically sits behind the firewall in a private network.