Hosting static website on EC2 Instance with Docker Container | AWS | EC2 | Docker Container

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
otherwise so in this tutorial we are going to host a static website on an ec2 instance with the help of a Docker container so basically we are going to containerize the an nginx web server where we are going to host our uh static website so first we have to create an ec2 instance and for that uh the step first one is first we are going to create an ec2 uh sorry ec2 Security Group with the port 80 and 422 is allowed on the inbound rule so let's go to the ec2 control first we have to create the security group for our ec2 instance I think I have already created one so let's create a new security group we are going to name it static WB group and allow Port 80 and 22 now we are going to add two rules uh first for first uh we have to allow SSH and uh we are going to set the road sources anywhere or you can also use set the my happy but I'm going to use this one and here we after that we have to add HTTP allow HTTP uh service on Port 80. save the settings and our security group is created now the second step is uh we and also second step is we have to create sorry ec2 instance but we also have to generate a key pair to in order to SSH into our ec2 instance so let's create keep here test key you can name it anything I'm going to generate a Pam private key because I'm going to use sh uh command line SSH now download the key and as you can see is uh and we have our created the key no let's create an instance I'm going to use Ubuntu Ami static site name is static site I'm going to select the Ubuntu uh image Ami image and the instance type is T2 micro and keep here I'm going to select the test key and for security groups um this is our security group static WB group and size will be the let's set it to 20 GB although we don't need 20gb but since we are going to run Docker container so we are going to set 20 GB and in advance in the details we are going to use cell script in order to provision the docker environment in the instance so I already wrote the provision script one minute here it is so this is our provision script let me move to that window so this is our provision script actually it is here also so uh this cell script is basically uh installed all the requirements and uh for a Docker container and we don't have to modify anything here but except that this username so this username basically indicates which user we are going to you you add onto the docker group so let's copy this and we have to modify basically change this one so since we are using Ubuntu Ami so the name would be Ubuntu and if you are using another and other Ami like Amazon Linux so you have to give appropriate name for example for a Amazon Linux ET users or something like that username is now just we have to launch the ec2 instance now the provision will take place and after that the our next step is uh step third is basically we have to create Docker file with nginx configuration so let's take a look at the docker file so basically uh commands so we are going to use a Docker image sorry sorry nginx latest image in order to build our Docker container and after that we are going to run the APT update and upgrade command and we are going to install uh W get and unzip binaries and work directory is default nginx uh root directory which is user share business and HTML and okay so we also have to write a nginx configuration file which is here so it basically uh said the uh sorry it basically uh Set uh the nginx to listen port number 80 and the root directory uh set the root directory to user share nginx and HTML and these are the basic configuration for uh nginx or nginx file and basically we have we are going to copy this uh in this line the copy command basically copy the nginx config default config to the ETC nginx sites enable directory which is basically where basically the nginx configuration file is get stored and for static website we are going to use uh this uh sample static website from a bootstrap mode sorry mate.com so in order to download uh get the link of the or get the download so you can get the download link from here and if you click here then it will automatically start the download uh then you can basically copy this URL oops it does I think it's download twice this URL and paste it here here basically in our configuration file so basically the eight command is so basically the eight command is going to copy the or download the uh G file into the workday directory and the second this command basically there are this command going to unzip the zip file and this is the and the next command basically uh copy all the files into the HTML directory and this command will remove the uh G file and the empty folder and the expose command will basically going to expose Port 80 and this is this the nginx G demon of command basically going to run the nginx file so these are the basic configuration and for the docker container file so now let's uh check the our ec2 instance now let's SSH into the instance connect and SSH client this is key and actually my key is basically downloaded on the download folder yep it's here so now let's SSH into the ec2 instance downloads and paste the command yes let's wait for some moment yeah now we are successfully SSH into the docker container now let's run the docker container docker hello world is basically uh actually my internet connection is a little bit slow so that's the reason behind leg a little bit lag hello oops I forget the Run command Docker run yep now it's working properly so now let's create the Docker file Docker file so I have already created the docker file for this so basically we just have to copy all these things you can find this code on my GitHub repository so don't worry about it and I already explained the code so now let's save it and also we have to uh create the nginx config file because the docker container basically going to copy this sorry Docker file basically going to copy the default conf to the this location so now let's copy this one also copy and VI default .com oops I typed VI twice now okay now let's uh create the docker image docker build t test IMG and version V1 Dot now it is basically going to create the image file side it doesn't take that much much of time or yeah because we are doing it inside the ec2 instance okay so everything is fine now let's look at the docker image okay so as you can see our test image is basically created now let's run the uh container by using let's sorry create the container by using this image so the command is docker run uh okay RM D we are going to run this in the background rmd and we have to expose we have to map the port 80 to 80. and what is the next command and I think everything is okay now let's give it the give the name of the image with tag and run the docker container now let's check docker PS now as you can see our container is running and Port 80 is exposed so now let's uh get the IP of our instance vc2 instance or sorry public IP so this is the for public our instance now let's copy the public DNS instead of the IP and paste it here and now let's visit that particular URL okay so as you can see we are able to access our uh static website which is which is running on the inside the docker container in ec2 instance and so that's it guys and if you want to check the docker content then we can also SSS uh sorry run a shell inside container sorry docker container exec ID and we have to use yep Dash so as you can see service and the next status yep it is running and we are in the working work directory so as you can see these are the files of our uh static website so that's it for the video guys thanks for watching the video
Info
Channel: DevOpsTech
Views: 2,672
Rating: undefined out of 5
Keywords:
Id: 47nHb27AxEk
Channel Id: undefined
Length: 13min 29sec (809 seconds)
Published: Sun Apr 02 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.