Hosted Webserver over Docker running on AWS

Published by Anubhav Singh on

In this article, we are going to host a webserver over the docker container using AWS EC2 service.

Task Description

  • Install Docker.
  • Pull a CentOS docker image.
  • Run a container of that image.
  • Install Apache Webserver.
  • Configure the server.

Note: I am using AWS to perform this task, you can use your own premises.

What is AWS?

AWS is a public cloud service provider that provides the computation power, storage service, content delivery service including a total of 175 services. AWS provides the infrastructure that we need and we have to pay on the basis of the uses. To know more about AWS you can read here…

What is Docker?

Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. It is really quick that it can provide install, boot, and run your application within seconds. To know more about docker you can read here…

In this task, I am not going to show you how to launch an EC2 instance. You can check this to know how to launch instance…

Task

Install Docker on AWS EC2

Boot your OS and open terminal.

In order to install the docker we have yum command and we are going to use ce version. Use below command to install

yum install docker-ce --nobest

I used nobest as because some version of linux conflicts with docker-ce version.

To start docker services use

systemctl start docker

This will start your docker services and to know the status we have

systemctl status docker

Pull a CentOS image

docker pull centos:latest

Using this I downloaded the latest OS image of CentOS and to check it is downloaded or not we have

docker images

Run Container

We are going launch webserver so that I am providing a port to this container.

docker run -itp 80:80 centos:latest

Once the container is launch we will go inside the container.

Install the Apache Webserver

Now to install the webserver use below command

yum install httpd

Configure the webserver

In order to configure the webserver we need to paste our code in /var/www/html folder.

and once the html file is created, our next step is to start the webserver. In normal OS of Linux we can start the server using systemctl command but container doesn’t support that. To start the server we have

/usr/sbin/httpd
netstat -tnlp

Using the above command we can confirm that port 80 is in use. We have successfully completed our setup. To check the webserver use ip:port. IP is of your OS and the port is what you have provided.

We have an additional task of running a python code.

To run a python code we need a python interpreter. To install the python interpreter I used

yum whatprovides python

and then use

yum install python36

Once installation is completed you can use python3 to start the interpreter

Hurrah! we have successfully completed our task.

Final Word

In case you want to learn more about the cloud you can go through this playlist Cloud Computing.

For such more updates stay tuned with BrighterBees

You can connect with the author on Twitter and Linkedin


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

STAY CONNECT WITH US