Deploying Docker compose on AWS EC2 and Exposing API

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
to do basically we are going to create a new ec2 instance on amazon web services after creating a new ec2 instance what we are going to do is we are going to deploy a docker compose file which will have two different images one is an api which is developed in rails and the second one is postgres database which connects to the api sales api okay and then we are going to expose so we can outside wall we can access it so here is something that you can see here i have loaded the data using the seed file from uh rails working here so let's get going the first thing we need to do is we can go to ec2 dashboard and then we can do a launch instance we can use the free tier eligible we can start and we can select the one that is free tier eligible so configure instance detail we will keep everything default for example network vpc and then subnet default no default subnet in and any availability to use this protect against accidental termination i will be basically removing this after i'm done with the video add storage let's keep it default whatever we have a tags uh for now i don't need any tags so i can do review and launch let's see previous okay create new security group okay yeah so one thing that we need to do for security group is we need to add room we need to add http and https okay and we are going to basically we need ssh in order to connect to our ec2 instance of amazon from the local machine and then we can do like some installation on the ec2 i'm going to keep the same default name security group name and all these things default i'm going to use a keypad that i generated earlier otherwise in your case you can click on create a new key pair here okay so as you can see i'm going to select what i already have so select a key pair which is this i acknowledge that i have access to this spam file launch instance we can click on view instance the one that is currently panning is this one i can click on this and then i can click copy this ipv4 address public address so i can go to terminal on the terminal you have to do ssh hyphen i name of the file that you have certified certificate or pam file and then ec2 user that is default at the rate ip address okay in my case the ip address is a new ip address that was the one i tried earlier so i'm going to use this but i have to wait until this is changes into running so let's get refresh this okay now it is running status check is initializing so i can go into this let me open up terminal let's try to connect first time you will see this basically fingerprint so you can say yes all right now i'm connected to ec2 instance okay so next thing we want to do is i have a documentation where we can go on to the documentation and start executing some commands in order to deploy and install docker on the ec2 instance okay so let's get going we can basically skip to this sudo yum install update y or let me do that just it doesn't hurt and then i have amazon linux2 so we can run this command in order to install docker it's installing then we can start the service yes you can modify and install to 43 megabytes of application sure now we are going to start the service docker service we need to add this user so we don't need any more uh pseudo command when the user executes all the different commands using docker and then let's verify okay did i miss something let's see got permission united cases as you can see here on the documentation it says cannot connect to demon is the demon running if you get this error we need to restart the service so let me log out log back in i'm not going for perfect it works now okay so now that we have a docker container running what i'm what i'm going to demonstrate is um i have a docker compose file i'm going to explain the docker compose file as well so let me create a docker style touch docker yml and then we can do vi doublecompost.com i as an insert paste i'm going to delete a volume since i was doing this locally escape dd escape dd for deleting a line um here the image i have created version 2 and why i'll explain why i too this might not work and i know why i have to modify the image so i'll modify the image let me put version three here skip column wq save and exit okay so let's create a version three so what we need for that we need to basically open this address copy this address and put it into the rails application so basically we have a development hyphen rb file let's go back development here config.host we need to add the host here so the rails will allow this will allow all these hosts which are white listed to query the application okay connect to our application and it will be of suppose all right so let's get going now what i what else i need to do here is i need to create this image again so i might have those commands here okay so i'm going to build an image version 3 then i'm going to create a tag here um where is my readme file here i have commands to create a tag and then push it to my docker hub this is my user id and then name of the image from my local machine what i'm trying to push onto the docker hub okay and similarly creating a tag what we need to do is this is the command docker image tag we are tagging the image name of the image that exists okay in this case i created a version 3 so i have to use column version 3 here and then my username and then the name of the image once that is done we can basically get docker oh in the meantime we can install docker compose so to install docker compose we have the new documentation from the docker itself so here we have a dockering documentation we can go to linux in the linux we can copy this command here we have to install that compose so let's install voila it's done now we can give permission after providing the permission we can create a sim link and then we can basically verify all right so we have a docker compose installed let's get back here now the new image is created so let me clear this docker images as you can see here we have a new image with version 3 which was created 54 seconds ago so let's create a tag so here i'm going to update the version version 3 here and same here version 3 create a tag now let's push it to the docker hub version three once i post this onto the docker hub all i need to do is i'm i can pull it i believe i have created this public so i can pull it from uh docker compose file without even login onto my docker hub from ec2 instance all right so it's already post so let's do docker compose up iphone hyphen detach so detach will run all the instances within the docker compose file of our images into the background okay so we have a postgres we have blog okay blog api developed in rails obviously this is not the best practice because as you can see here you can see the username and password the purpose of this video is to demonstrate how to basically create the environment and set it up you will need to do more thorough investigation i mean research on how to basically use docker secrets in order to hide your password and everything so as you can see here we created two different uh containers so let me clear the screen docker ps ps will show the processes that are running right now so we have two different processes one we have a blog api which is connected to postgres database but in order to connect we need to create those database from the blog okay so let me log into this container running container docker exact iphone interactive container id and then bash so now i can execute the command so bundle exact break db create this created a database and then i can do migrate to migrate the data and then we'll see the data so this is seeded already and then we can go back to our instance open up the public address so we have okay one mistake i made here is port 3000 it is redirecting to port 3000 which i need to update so docker compose stop clear the vi compose ammo interactive here uh for my api i need to expose it to 80 port 80 escape column wq so now i can do local composer in detach mode now you can see it is redirected to port 80 localhost so let's get as you can see now we are connected to rails so let's it's plural okay and then we can see post so exceeded this data from the docker rails api so let me show you docker extract iphone it interactive then i can go into this blog and then bash so ls cd db let's get seeds notice here i have added some of the data which we are seeing from the eba so thank you for watching this video i'll see you on the next video please read and comment so i can provide better and more information about development i'll see you on the next time
Info
Channel: ProgrammingHumanWay
Views: 1,949
Rating: 5 out of 5
Keywords: aws-ec2, aws, aws-docker, aws-docker-compose, aws-deploy-docker-image, docker, docker-compose-aws-ec2-installation-setup, software-engineering, aws-cloud, docer-compose
Id: FVNBdylX5po
Channel Id: undefined
Length: 14min 52sec (892 seconds)
Published: Wed Jun 30 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.