Research: Configuration of multiple WEB SERVERS on Docker Containers along with Host Computer Web Server on the top of AWS
"Configuration of multiple WEB SERVERS on Docker Containers along with Host Computer Web Server on the top of AWS" designed by Shobhit Sharma aka ScriptKKiddie

Research: Configuration of multiple WEB SERVERS on Docker Containers along with Host Computer Web Server on the top of AWS

Docker is a set of the platform as service products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries, and configuration files; they can communicate with each other through well-defined channels. ~

Wikipedia

In the automation world, technologies like docker are very helpful to run multiple operating systems, web apps, applications in a second. These OS, web apps, or applications in terms of Docker also known as Containers.

Configuring multiple web servers on different docker containers for a purpose is possible in a Containerization system. These services run on different containers and all the containers run on the host computer.

The docker also provides different networking features like a bridge, an overlay, a macvlan network, etc., also known as Container networking.

Using container networking, the host and containers can be connected with each other. To connect the docker container outside the host, the Port mapping concept used in this scenario. By default, when Docker starts, a default bridge network (also called a bridge) is created automatically, and newly-started containers connect to it unless otherwise specified.

According to Docker, the default bridge network is considered a legacy detail of Docker and is not recommended for production use.

Bridge network

In terms of networking, a bridge network is a Link Layer device which forwards traffic between network segments. A bridge can be a hardware device or a software device running within a host machine’s kernel.

In terms of Docker, a bridge network uses a software bridge which allows containers connected to the same bridge network to communicate, while providing isolation from containers which are not connected to that bridge network. The Docker bridge driver automatically installs rules in the host machine so that containers on different bridge networks cannot communicate directly with each other.

The network named bridge is a special network. Unless we tell it otherwise, Docker always launches our containers in this network.

The docker container is connecting with host using bridge network connection named "docker0"

Following the same procedures, I'll show you how can we run multiple web servers on docker containers along with the host computer web server on the top of AWS and accessing them using Public IP Address.


Configuring "httpd" Apache HTTP Server on "RHEL8" EC2 Instance in AWS

In this section, I'll configure the "httpd" Web Server on the Host Computer where Docker is running on EC2 Instance in AWS. To configure httpd, we need to follow the below steps

Step 1) First of all, we need to install httpd using the following command

yum install httpd

& The output will be

Last metadata expiration check: 1:11:36 ago on Tue 17 Nov 2020 04:40:38 AM UTC.
Dependencies resolved.
================================================================================
 Package            Arch   Version             Repository                  Size
================================================================================
Installing:
 httpd              x86_64 2.4.37-30.module+el8.3.0+7001+0766b9e7
                                               rhel-8-appstream-rhui-rpms 1.4 M
Installing dependencies:
 apr                x86_64 1.6.3-11.el8        rhel-8-appstream-rhui-rpms 125 k
 apr-util           x86_64 1.6.1-6.el8         rhel-8-appstream-rhui-rpms 105 k
 httpd-filesystem   noarch 2.4.37-30.module+el8.3.0+7001+0766b9e7
                                               rhel-8-appstream-rhui-rpms  37 k
 httpd-tools        x86_64 2.4.37-30.module+el8.3.0+7001+0766b9e7
                                               rhel-8-appstream-rhui-rpms 104 k
 mailcap            noarch 2.1.48-3.el8        rhel-8-baseos-rhui-rpms     39 k
 mod_http2          x86_64 1.15.7-2.module+el8.3.0+7670+8bf57d29
                                               rhel-8-appstream-rhui-rpms 154 k
 redhat-logos-httpd noarch 81.1-1.el8          rhel-8-baseos-rhui-rpms     26 k
Installing weak dependencies:
 apr-util-bdb       x86_64 1.6.1-6.el8         rhel-8-appstream-rhui-rpms  25 k
 apr-util-openssl   x86_64 1.6.1-6.el8         rhel-8-appstream-rhui-rpms  27 k
Enabling module streams:
 httpd                     2.4

Transaction Summary
================================================================================
Install  10 Packages

Total download size: 2.0 M
Installed size: 5.4 M
Is this ok [y/N]: y
Downloading Packages:
(1/10): apr-util-bdb-1.6.1-6.el8.x86_64.rpm     213 kB/s |  25 kB     00:00
(2/10): apr-util-openssl-1.6.1-6.el8.x86_64.rpm 227 kB/s |  27 kB     00:00
(3/10): apr-util-1.6.1-6.el8.x86_64.rpm         846 kB/s | 105 kB     00:00
(4/10): httpd-filesystem-2.4.37-30.module+el8.3 408 kB/s |  37 kB     00:00
(5/10): httpd-tools-2.4.37-30.module+el8.3.0+70 1.0 MB/s | 104 kB     00:00
(6/10): apr-1.6.3-11.el8.x86_64.rpm             1.2 MB/s | 125 kB     00:00
(7/10): mod_http2-1.15.7-2.module+el8.3.0+7670+ 1.6 MB/s | 154 kB     00:00
(8/10): httpd-2.4.37-30.module+el8.3.0+7001+076 9.8 MB/s | 1.4 MB     00:00
(9/10): mailcap-2.1.48-3.el8.noarch.rpm         312 kB/s |  39 kB     00:00
(10/10): redhat-logos-httpd-81.1-1.el8.noarch.r 269 kB/s |  26 kB     00:00
--------------------------------------------------------------------------------
Total                                           3.2 MB/s | 2.0 MB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Installing       : apr-1.6.3-11.el8.x86_64                               1/10
  Running scriptlet: apr-1.6.3-11.el8.x86_64                               1/10
/sbin/ldconfig: /lib64/libhdfs.so.0 is not a symbolic link

/sbin/ldconfig: /lib64/libhadoop.so.1 is not a symbolic link


  Installing       : apr-util-openssl-1.6.1-6.el8.x86_64                   2/10
  Installing       : apr-util-1.6.1-6.el8.x86_64                           3/10
  Running scriptlet: apr-util-1.6.1-6.el8.x86_64                           3/10
/sbin/ldconfig: /lib64/libhdfs.so.0 is not a symbolic link

/sbin/ldconfig: /lib64/libhadoop.so.1 is not a symbolic link


  Installing       : apr-util-bdb-1.6.1-6.el8.x86_64                       4/10
  Installing       : httpd-tools-2.4.37-30.module+el8.3.0+7001+0766b9e7    5/10
  Installing       : redhat-logos-httpd-81.1-1.el8.noarch                  6/10
  Installing       : mailcap-2.1.48-3.el8.noarch                           7/10
  Running scriptlet: httpd-filesystem-2.4.37-30.module+el8.3.0+7001+076    8/10
  Installing       : httpd-filesystem-2.4.37-30.module+el8.3.0+7001+076    8/10
  Installing       : mod_http2-1.15.7-2.module+el8.3.0+7670+8bf57d29.x8    9/10
  Installing       : httpd-2.4.37-30.module+el8.3.0+7001+0766b9e7.x86_6   10/10
  Running scriptlet: httpd-2.4.37-30.module+el8.3.0+7001+0766b9e7.x86_6   10/10
/sbin/ldconfig: /lib64/libhdfs.so.0 is not a symbolic link

/sbin/ldconfig: /lib64/libhadoop.so.1 is not a symbolic link


  Verifying        : apr-util-bdb-1.6.1-6.el8.x86_64                       1/10
  Verifying        : apr-util-openssl-1.6.1-6.el8.x86_64                   2/10
  Verifying        : apr-util-1.6.1-6.el8.x86_64                           3/10
  Verifying        : httpd-tools-2.4.37-30.module+el8.3.0+7001+0766b9e7    4/10
  Verifying        : httpd-filesystem-2.4.37-30.module+el8.3.0+7001+076    5/10
  Verifying        : apr-1.6.3-11.el8.x86_64                               6/10
  Verifying        : httpd-2.4.37-30.module+el8.3.0+7001+0766b9e7.x86_6    7/10
  Verifying        : mod_http2-1.15.7-2.module+el8.3.0+7670+8bf57d29.x8    8/10
  Verifying        : mailcap-2.1.48-3.el8.noarch                           9/10
  Verifying        : redhat-logos-httpd-81.1-1.el8.noarch                 10/10

Installed:
  apr-1.6.3-11.el8.x86_64
  apr-util-1.6.1-6.el8.x86_64
  apr-util-bdb-1.6.1-6.el8.x86_64
  apr-util-openssl-1.6.1-6.el8.x86_64
  httpd-2.4.37-30.module+el8.3.0+7001+0766b9e7.x86_64
  httpd-filesystem-2.4.37-30.module+el8.3.0+7001+0766b9e7.noarch
  httpd-tools-2.4.37-30.module+el8.3.0+7001+0766b9e7.x86_64
  mailcap-2.1.48-3.el8.noarch
  mod_http2-1.15.7-2.module+el8.3.0+7670+8bf57d29.x86_64
  redhat-logos-httpd-81.1-1.el8.noarch

Complete!

Step 2) After that, we need to run the httpd service by using the following command

systemctl start httpd

This will start httpd service, and it can be checked using the EC2 Instance public IP address from the client browser

https://<public_ip_address>

The output will be

No alt text provided for this image

Great! It works fine...

Additional step) Creating a static HTML page for testing, we need to follow the commands below

Changing directory from root to HTML where the static pages saved for hosting

cd /var/www/html/

In this directory, I'll create a static page named "shobhit.html" and add some static content by using the following command

vi shobhit.html

& the content which I'm gonna write

<h1>Host Machine running on default port 80</h1>
<h2>This is Shobhit Sharma's page</h2>

& then save it by pressing Esc and ":wq" + Enter

Visit https://<public_ip>/shobhit.html

The output will be

No alt text provided for this image

& this page is served at <public_ip> and port 80.

That's all


Launching "CentOS" Docker Containers and configuring "httpd" Web Servers

Before performing this operation, we need to understand the following terms

Port mapping

By default, when we create or run a container using docker create or docker run, it does not publish any of its ports to the outside world. To make a port available to services outside of Docker, or to Docker containers which are not connected to the container’s network, we use the --publish or -p flag. This creates a firewall rule which maps a container port to a port on the Docker host to the outside world.

The syntax for -p is HOST_PORT:CLIENT_PORT

When we run a container with the -p argument, for example:

$ docker run -p 80:80 -d nginx

Docker makes whatever is running on port 80 in the container (in this case, nginx) available on port 80 of localhost. In this example, the host and container ports are the same. What if we need to specify a different host port? for example, we already have something running on port 80 of our host machine, we can connect the container to a different port:

$ docker run -p 8000:80 -d nginx

Now, connections to localhost:8000 are sent to port 80 in the container.

That's all

Now, I am gonna create two different Docker containers to run multiple Web Servers

Launching the first "CentOS" Docker Container and configuring "httpd" Web Server

For the first "CentOS" Docker Container, I am gonna use the following details

  1. Name - dockerWebServer001
  2. Port - 1010

For setting up the docker container, we need to follow the below steps

Step 1) First of all, to launch the docker container we need to run the following command

docker run -it -p 1010:80 --name dockerWebServer001 centos:latest

The output will be

Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
[root@4ac38d40ee52 /]#

where root@4ac38d40ee53 is the new docker container terminal, it is showing that we are not in the host machine or we're logged into the docker container terminal

Step 2) Now, we need to install some of the packages as prerequisites

  1. net-tools - includes ifconfig and other commands
  2. which - used to check software, program, or package directory

To install these tools, we need to run the following commands

For net-tools

dnf install net-tools

The output will be

Failed to set locale, defaulting to C.UTF-8
CentOS-8 - AppStream                             11 MB/s | 5.8 MB     00:00
CentOS-8 - Base                                 4.6 MB/s | 2.2 MB     00:00
CentOS-8 - Extras                                43 kB/s | 8.6 kB     00:00
Dependencies resolved.
================================================================================
 Package         Architecture Version                        Repository    Size
================================================================================
Installing:
 net-tools       x86_64       2.0-0.51.20160912git.el8       BaseOS       323 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 323 k
Installed size: 1.0 M
Is this ok [y/N]: y
Downloading Packages:
net-tools-2.0-0.51.20160912git.el8.x86_64.rpm   2.5 MB/s | 323 kB     00:00
--------------------------------------------------------------------------------
Total                                           1.0 MB/s | 323 kB     00:00
warning: /var/cache/dnf/BaseOS-f6a80ba95cf937f2/packages/net-tools-2.0-0.51.20160912git.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
CentOS-8 - Base                                 1.6 MB/s | 1.6 kB     00:00
Importing GPG key 0x8483C65D:
 Userid     : "CentOS (CentOS Official Signing Key) <[email protected]>"
 Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Installing       : net-tools-2.0-0.51.20160912git.el8.x86_64              1/1
  Running scriptlet: net-tools-2.0-0.51.20160912git.el8.x86_64              1/1
  Verifying        : net-tools-2.0-0.51.20160912git.el8.x86_64              1/1

Installed:
  net-tools-2.0-0.51.20160912git.el8.x86_64

Complete!

For which

dnf install which

The output will be

Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:00:19 ago on Tue Nov 17 06:02:16 2020.
Dependencies resolved.
================================================================================
 Package         Architecture     Version                Repository        Size
================================================================================
Installing:
 which           x86_64           2.21-12.el8            BaseOS            49 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 49 k
Installed size: 81 k
Is this ok [y/N]: y
Downloading Packages:
which-2.21-12.el8.x86_64.rpm                    456 kB/s |  49 kB     00:00
--------------------------------------------------------------------------------
Total                                           403 kB/s |  49 kB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Installing       : which-2.21-12.el8.x86_64                               1/1
  Running scriptlet: which-2.21-12.el8.x86_64                               1/1
  Verifying        : which-2.21-12.el8.x86_64                               1/1

Installed:
  which-2.21-12.el8.x86_64

Complete!

Step 3) Now, we need to run the following command to install the httpd

dnf install httpd

The output will be

Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:00:37 ago on Tue Nov 17 06:02:16 2020.
Dependencies resolved.
================================================================================
 Package          Arch   Version                                Repo       Size
================================================================================
Installing:
 httpd            x86_64 2.4.37-21.module_el8.2.0+494+1df74eae  AppStream 1.7 M
Installing dependencies:
 apr              x86_64 1.6.3-9.el8                            AppStream 125 k
 apr-util         x86_64 1.6.1-6.el8                            AppStream 105 k
 brotli           x86_64 1.0.6-1.el8                            BaseOS    323 k
 centos-logos-httpd
                  noarch 80.5-2.el8                             BaseOS     24 k
 httpd-filesystem noarch 2.4.37-21.module_el8.2.0+494+1df74eae  AppStream  36 k
 httpd-tools      x86_64 2.4.37-21.module_el8.2.0+494+1df74eae  AppStream 103 k
 mailcap          noarch 2.1.48-3.el8                           BaseOS     39 k
 mod_http2        x86_64 1.11.3-3.module_el8.2.0+486+c01050f0.1 AppStream 156 k
Installing weak dependencies:
 apr-util-bdb     x86_64 1.6.1-6.el8                            AppStream  25 k
 apr-util-openssl x86_64 1.6.1-6.el8                            AppStream  27 k
Enabling module streams:
 httpd                   2.4

Transaction Summary
================================================================================
Install  11 Packages

Total download size: 2.6 M
Installed size: 7.5 M
Is this ok [y/N]: y
Downloading Packages:
(1/11): apr-util-bdb-1.6.1-6.el8.x86_64.rpm     467 kB/s |  25 kB     00:00
(2/11): apr-util-openssl-1.6.1-6.el8.x86_64.rpm 966 kB/s |  27 kB     00:00
(3/11): apr-util-1.6.1-6.el8.x86_64.rpm         1.1 MB/s | 105 kB     00:00
(4/11): apr-1.6.3-9.el8.x86_64.rpm              1.3 MB/s | 125 kB     00:00
[MIRROR] httpd-filesystem-2.4.37-21.module_el8.2.0+494+1df74eae.noarch.rpm: Status code: 404 for https://d36uatko69830t.cloudfront.net/centos/8/AppStream/x86_64/os/Packages/httpd-filesystem-2.4.37-21.module_el8.2.0+494+1df74eae.noarch.rpm (IP: 13.33.155.208)
[MIRROR] httpd-2.4.37-21.module_el8.2.0+494+1df74eae.x86_64.rpm: Status code: 404 for https://d36uatko69830t.cloudfront.net/centos/8/AppStream/x86_64/os/Packages/httpd-2.4.37-21.module_el8.2.0+494+1df74eae.x86_64.rpm (IP: 13.33.155.208)
[MIRROR] httpd-tools-2.4.37-21.module_el8.2.0+494+1df74eae.x86_64.rpm: Status code: 404 for https://d36uatko69830t.cloudfront.net/centos/8/AppStream/x86_64/os/Packages/httpd-tools-2.4.37-21.module_el8.2.0+494+1df74eae.x86_64.rpm (IP: 13.33.155.208)
(5/11): httpd-filesystem-2.4.37-21.module_el8.2 111 kB/s |  36 kB     00:00
(6/11): httpd-tools-2.4.37-21.module_el8.2.0+49 277 kB/s | 103 kB     00:00
(7/11): mod_http2-1.11.3-3.module_el8.2.0+486+c 1.9 MB/s | 156 kB     00:00
(8/11): centos-logos-httpd-80.5-2.el8.noarch.rp 1.0 MB/s |  24 kB     00:00
(9/11): brotli-1.0.6-1.el8.x86_64.rpm           5.4 MB/s | 323 kB     00:00
(10/11): mailcap-2.1.48-3.el8.noarch.rpm        1.6 MB/s |  39 kB     00:00
(11/11): httpd-2.4.37-21.module_el8.2.0+494+1df 3.2 MB/s | 1.7 MB     00:00
--------------------------------------------------------------------------------
Total                                           2.8 MB/s | 2.6 MB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Installing       : apr-1.6.3-9.el8.x86_64                                1/11
  Running scriptlet: apr-1.6.3-9.el8.x86_64                                1/11
  Installing       : apr-util-bdb-1.6.1-6.el8.x86_64                       2/11
  Installing       : apr-util-openssl-1.6.1-6.el8.x86_64                   3/11
  Installing       : apr-util-1.6.1-6.el8.x86_64                           4/11
  Running scriptlet: apr-util-1.6.1-6.el8.x86_64                           4/11
  Installing       : httpd-tools-2.4.37-21.module_el8.2.0+494+1df74eae.    5/11
  Installing       : mailcap-2.1.48-3.el8.noarch                           6/11
  Installing       : centos-logos-httpd-80.5-2.el8.noarch                  7/11
  Installing       : brotli-1.0.6-1.el8.x86_64                             8/11
  Running scriptlet: httpd-filesystem-2.4.37-21.module_el8.2.0+494+1df7    9/11
  Installing       : httpd-filesystem-2.4.37-21.module_el8.2.0+494+1df7    9/11
  Installing       : mod_http2-1.11.3-3.module_el8.2.0+486+c01050f0.1.x   10/11
  Installing       : httpd-2.4.37-21.module_el8.2.0+494+1df74eae.x86_64   11/11
  Running scriptlet: httpd-2.4.37-21.module_el8.2.0+494+1df74eae.x86_64   11/11
  Verifying        : apr-1.6.3-9.el8.x86_64                                1/11
  Verifying        : apr-util-1.6.1-6.el8.x86_64                           2/11
  Verifying        : apr-util-bdb-1.6.1-6.el8.x86_64                       3/11
  Verifying        : apr-util-openssl-1.6.1-6.el8.x86_64                   4/11
  Verifying        : httpd-2.4.37-21.module_el8.2.0+494+1df74eae.x86_64    5/11
  Verifying        : httpd-filesystem-2.4.37-21.module_el8.2.0+494+1df7    6/11
  Verifying        : httpd-tools-2.4.37-21.module_el8.2.0+494+1df74eae.    7/11
  Verifying        : mod_http2-1.11.3-3.module_el8.2.0+486+c01050f0.1.x    8/11
  Verifying        : brotli-1.0.6-1.el8.x86_64                             9/11
  Verifying        : centos-logos-httpd-80.5-2.el8.noarch                 10/11
  Verifying        : mailcap-2.1.48-3.el8.noarch                          11/11

Installed:
  apr-1.6.3-9.el8.x86_64
  apr-util-1.6.1-6.el8.x86_64
  apr-util-bdb-1.6.1-6.el8.x86_64
  apr-util-openssl-1.6.1-6.el8.x86_64
  brotli-1.0.6-1.el8.x86_64
  centos-logos-httpd-80.5-2.el8.noarch
  httpd-2.4.37-21.module_el8.2.0+494+1df74eae.x86_64
  httpd-filesystem-2.4.37-21.module_el8.2.0+494+1df74eae.noarch
  httpd-tools-2.4.37-21.module_el8.2.0+494+1df74eae.x86_64
  mailcap-2.1.48-3.el8.noarch
  mod_http2-1.11.3-3.module_el8.2.0+486+c01050f0.1.x86_64

Complete!

Step 4) After that, we need to start the httpd service by running the following commands

First, we need to check the directory of httpd to run the httpd service directly (Due to some reasons, by default docker doesn't run services using "systemctl" command)

which httpd

This will show the directory for httpd

/usr/sbin/httpd

Now, we can run httpd using "/usr/sbin/httpd" and the output will be

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.88.0.6. Set the 'ServerName' directive globally to suppress this message

& Ignore this message, the httpd service is successfully started after this.

Step 5) Now, we can check whether the httpd service is started or not. According to the configuration, The port is active for HTTP Service on 1010

We can directly access this using AWS Public IP Address

https://<public_ip>:1010

No alt text provided for this image

Great! It works fine...

Additional step) Creating a static HTML page for testing, we need to follow the commands below

Changing directory from root to HTML where the static pages saved for hosting

cd /var/www/html/

In this directory, I'll create a static page named "shobhit.html" and add some static content by using the following command

vi shobhit.html

& the content which I'm gonna write

<h1>Docker1 Image running on port 1010</h1>
<h2>This is Shobhit Sharma's page</h2>

& then save it by pressing Esc and ":wq" + Enter

Visit https://<public_ip>:1010/shobhit.html

The output will be

No alt text provided for this image

& this page is served at <public_ip> and port 1010.

That's all

Creating the second "CentOS" Docker Container and configuring "httpd" Web Server

For the second "CentOS" Docker Container, I am gonna use the following details

  1. Name - dockerWebServer002
  2. Port - 2020

For setting up the docker container, we need to follow the below steps

Step 1) First of all, to launch a docker container we need to run the following command

docker run -it -p 2020:80 --name dockerWebServer002 centos:latest

The output will be

Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
[root@9ab4050771aa /]#

where root@9ab4050771aa is the new docker container terminal, it is showing that we are not in the host machine or we're logged into the docker container terminal

Step 2) Now, we need to install some of the packages as prerequisites

  1. net-tools - includes ifconfig and other commands
  2. which - used to check software, program, or package directory

To install these tools, we need to run the following commands

For net-tools

dnf install net-tools

The output will be

Failed to set locale, defaulting to C.UTF-8
CentOS-8 - AppStream                             14 MB/s | 5.8 MB     00:00
CentOS-8 - Base                                 5.4 MB/s | 2.2 MB     00:00
CentOS-8 - Extras                                36 kB/s | 8.6 kB     00:00
Dependencies resolved.
================================================================================
 Package         Architecture Version                        Repository    Size
================================================================================
Installing:
 net-tools       x86_64       2.0-0.51.20160912git.el8       BaseOS       323 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 323 k
Installed size: 1.0 M
Is this ok [y/N]: y
Downloading Packages:
net-tools-2.0-0.51.20160912git.el8.x86_64.rpm   2.5 MB/s | 323 kB     00:00
--------------------------------------------------------------------------------
Total                                           856 kB/s | 323 kB     00:00
warning: /var/cache/dnf/BaseOS-f6a80ba95cf937f2/packages/net-tools-2.0-0.51.20160912git.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
CentOS-8 - Base                                 1.6 MB/s | 1.6 kB     00:00
Importing GPG key 0x8483C65D:
 Userid     : "CentOS (CentOS Official Signing Key) <[email protected]>"
 Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Installing       : net-tools-2.0-0.51.20160912git.el8.x86_64              1/1
  Running scriptlet: net-tools-2.0-0.51.20160912git.el8.x86_64              1/1
  Verifying        : net-tools-2.0-0.51.20160912git.el8.x86_64              1/1

Installed:
  net-tools-2.0-0.51.20160912git.el8.x86_64

Complete!

For which

dnf install which

The output will be

Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:00:18 ago on Tue Nov 17 06:07:11 2020.
Dependencies resolved.
================================================================================
 Package         Architecture     Version                Repository        Size
================================================================================
Installing:
 which           x86_64           2.21-12.el8            BaseOS            49 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 49 k
Installed size: 81 k
Is this ok [y/N]: y
Downloading Packages:
which-2.21-12.el8.x86_64.rpm                    677 kB/s |  49 kB     00:00
--------------------------------------------------------------------------------
Total                                           132 kB/s |  49 kB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Installing       : which-2.21-12.el8.x86_64                               1/1
  Running scriptlet: which-2.21-12.el8.x86_64                               1/1
  Verifying        : which-2.21-12.el8.x86_64                               1/1

Installed:
  which-2.21-12.el8.x86_64

Complete!

Step 3) Now, we need to run the following command to install the httpd

dnf install httpd

The output will be

Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:00:27 ago on Tue Nov 17 06:07:11 2020.
Dependencies resolved.
================================================================================
 Package          Arch   Version                                Repo       Size
================================================================================
Installing:
 httpd            x86_64 2.4.37-21.module_el8.2.0+494+1df74eae  AppStream 1.7 M
Installing dependencies:
 apr              x86_64 1.6.3-9.el8                            AppStream 125 k
 apr-util         x86_64 1.6.1-6.el8                            AppStream 105 k
 brotli           x86_64 1.0.6-1.el8                            BaseOS    323 k
 centos-logos-httpd
                  noarch 80.5-2.el8                             BaseOS     24 k
 httpd-filesystem noarch 2.4.37-21.module_el8.2.0+494+1df74eae  AppStream  36 k
 httpd-tools      x86_64 2.4.37-21.module_el8.2.0+494+1df74eae  AppStream 103 k
 mailcap          noarch 2.1.48-3.el8                           BaseOS     39 k
 mod_http2        x86_64 1.11.3-3.module_el8.2.0+486+c01050f0.1 AppStream 156 k
Installing weak dependencies:
 apr-util-bdb     x86_64 1.6.1-6.el8                            AppStream  25 k
 apr-util-openssl x86_64 1.6.1-6.el8                            AppStream  27 k
Enabling module streams:
 httpd                   2.4

Transaction Summary
================================================================================
Install  11 Packages

Total download size: 2.6 M
Installed size: 7.5 M
Is this ok [y/N]: y
Downloading Packages:
(1/11): apr-util-bdb-1.6.1-6.el8.x86_64.rpm     497 kB/s |  25 kB     00:00
(2/11): apr-util-openssl-1.6.1-6.el8.x86_64.rpm 1.1 MB/s |  27 kB     00:00
(3/11): apr-util-1.6.1-6.el8.x86_64.rpm         1.2 MB/s | 105 kB     00:00
(4/11): apr-1.6.3-9.el8.x86_64.rpm              1.3 MB/s | 125 kB     00:00
[MIRROR] httpd-filesystem-2.4.37-21.module_el8.2.0+494+1df74eae.noarch.rpm: Status code: 404 for https://d36uatko69830t.cloudfront.net/centos/8/AppStream/x86_64/os/Packages/httpd-filesystem-2.4.37-21.module_el8.2.0+494+1df74eae.noarch.rpm (IP: 13.33.155.222)
[MIRROR] httpd-tools-2.4.37-21.module_el8.2.0+494+1df74eae.x86_64.rpm: Status code: 404 for https://d36uatko69830t.cloudfront.net/centos/8/AppStream/x86_64/os/Packages/httpd-tools-2.4.37-21.module_el8.2.0+494+1df74eae.x86_64.rpm (IP: 13.33.155.222)
[MIRROR] httpd-2.4.37-21.module_el8.2.0+494+1df74eae.x86_64.rpm: Status code: 404 for https://d36uatko69830t.cloudfront.net/centos/8/AppStream/x86_64/os/Packages/httpd-2.4.37-21.module_el8.2.0+494+1df74eae.x86_64.rpm (IP: 13.33.155.222)
(5/11): httpd-filesystem-2.4.37-21.module_el8.2  99 kB/s |  36 kB     00:00
(6/11): httpd-tools-2.4.37-21.module_el8.2.0+49 252 kB/s | 103 kB     00:00
(7/11): mod_http2-1.11.3-3.module_el8.2.0+486+c 1.7 MB/s | 156 kB     00:00
(8/11): brotli-1.0.6-1.el8.x86_64.rpm           5.7 MB/s | 323 kB     00:00
(9/11): centos-logos-httpd-80.5-2.el8.noarch.rp 1.0 MB/s |  24 kB     00:00
(10/11): mailcap-2.1.48-3.el8.noarch.rpm        1.7 MB/s |  39 kB     00:00
(11/11): httpd-2.4.37-21.module_el8.2.0+494+1df 2.8 MB/s | 1.7 MB     00:00
--------------------------------------------------------------------------------
Total                                           2.5 MB/s | 2.6 MB     00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Installing       : apr-1.6.3-9.el8.x86_64                                1/11
  Running scriptlet: apr-1.6.3-9.el8.x86_64                                1/11
  Installing       : apr-util-bdb-1.6.1-6.el8.x86_64                       2/11
  Installing       : apr-util-openssl-1.6.1-6.el8.x86_64                   3/11
  Installing       : apr-util-1.6.1-6.el8.x86_64                           4/11
  Running scriptlet: apr-util-1.6.1-6.el8.x86_64                           4/11
  Installing       : httpd-tools-2.4.37-21.module_el8.2.0+494+1df74eae.    5/11
  Installing       : mailcap-2.1.48-3.el8.noarch                           6/11
  Installing       : centos-logos-httpd-80.5-2.el8.noarch                  7/11
  Installing       : brotli-1.0.6-1.el8.x86_64                             8/11
  Running scriptlet: httpd-filesystem-2.4.37-21.module_el8.2.0+494+1df7    9/11
  Installing       : httpd-filesystem-2.4.37-21.module_el8.2.0+494+1df7    9/11
  Installing       : mod_http2-1.11.3-3.module_el8.2.0+486+c01050f0.1.x   10/11
  Installing       : httpd-2.4.37-21.module_el8.2.0+494+1df74eae.x86_64   11/11
  Running scriptlet: httpd-2.4.37-21.module_el8.2.0+494+1df74eae.x86_64   11/11
  Verifying        : apr-1.6.3-9.el8.x86_64                                1/11
  Verifying        : apr-util-1.6.1-6.el8.x86_64                           2/11
  Verifying        : apr-util-bdb-1.6.1-6.el8.x86_64                       3/11
  Verifying        : apr-util-openssl-1.6.1-6.el8.x86_64                   4/11
  Verifying        : httpd-2.4.37-21.module_el8.2.0+494+1df74eae.x86_64    5/11
  Verifying        : httpd-filesystem-2.4.37-21.module_el8.2.0+494+1df7    6/11
  Verifying        : httpd-tools-2.4.37-21.module_el8.2.0+494+1df74eae.    7/11
  Verifying        : mod_http2-1.11.3-3.module_el8.2.0+486+c01050f0.1.x    8/11
  Verifying        : brotli-1.0.6-1.el8.x86_64                             9/11
  Verifying        : centos-logos-httpd-80.5-2.el8.noarch                 10/11
  Verifying        : mailcap-2.1.48-3.el8.noarch                          11/11

Installed:
  apr-1.6.3-9.el8.x86_64
  apr-util-1.6.1-6.el8.x86_64
  apr-util-bdb-1.6.1-6.el8.x86_64
  apr-util-openssl-1.6.1-6.el8.x86_64
  brotli-1.0.6-1.el8.x86_64
  centos-logos-httpd-80.5-2.el8.noarch
  httpd-2.4.37-21.module_el8.2.0+494+1df74eae.x86_64
  httpd-filesystem-2.4.37-21.module_el8.2.0+494+1df74eae.noarch
  httpd-tools-2.4.37-21.module_el8.2.0+494+1df74eae.x86_64
  mailcap-2.1.48-3.el8.noarch
  mod_http2-1.11.3-3.module_el8.2.0+486+c01050f0.1.x86_64

Complete!

Step 4) After that, we need to start the httpd service by running the following commands

First, we need to check the directory of httpd to run the httpd service directly (Due to some reasons, by default docker doesn't run services using "systemctl" command)

which httpd

This will show the directory for httpd

/usr/sbin/httpd

Now, we can run httpd using "/usr/sbin/httpd" and the output will be

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.88.0.7. Set the 'ServerName' directive globally to suppress this message

& Ignore this message, the httpd service is successfully started after this.

Step 5) Now, we can check whether the httpd service is started or not. According to the configuration, The port is active for HTTP Service on 2020

We can directly access this using AWS Public IP Address

https://<public_ip>:2020

No alt text provided for this image

Great! It works fine...

Additional step) Creating a static HTML page for testing, we need to follow the commands below

Changing directory from root to HTML where the static pages saved for hosting

cd /var/www/html/

In this directory, I'll create a static page named "shobhit.html" and add some static content by using the following command

vi shobhit.html

& the content which I'm gonna write

<h1>Docker2 Image running on port 2020</h1>
<h2>This is Shobhit Sharma's page</h2>

& then save it by pressing Esc and ":wq" + Enter

Visit https://<public_ip>:2020/shobhit.html

The output will be

No alt text provided for this image

& this page is served at <public_ip> and port 2020.

That's all

Now, we can directly check all the running web servers on docker containers and host machine separately

No alt text provided for this image


How can it be accessible using Public IP?

Because in AWS Network Infrastructure, the EC2 Instance (host computer) is connected with WAN and has its own public IP. The bridge networking in Docker connects containers and host with each other. So, it can be accessed using Public IP. One more thing, the Docker Containers acts as services that's why for Host Computer, each docker container should have their unique Port number for HTTP Server in this scenario.**


Conclusion

The final conclusion is that we can run multiple web servers on multiple Docker containers along with a Host computer web server on the top of AWS Cloud and can access them using the same public IP Address with different ports.

This is how we can configure multiple WEB SERVERS on Docker Containers along with Host Computer Web Server on the top of AWS

***

This article is written, edited, and published by Shobhit Sharma.

IMPORTANT!: **The practical implementation is currently being modified according to research. Each concept and theory might be changed.

For more information regarding this article topic, kindly contact me via email: [email protected]

Thanks for reading!!!

Connect With Me On Twitter | LinkedIn | Facebook | Instagram

Alejandro Casado Gonzalez

Estudiante en IES Camp De Morvedre

2 年

Awesome! Thanks you!

要查看或添加评论,请登录

社区洞察

其他会员也浏览了