Docker expose, Learn to host website in container, AWS Ec2-instance.
Hello Friends,
In this article, I have explain how deployed website in container and enable the container port and ec2-instance port.
First, you have to launch ec2-instance. Please follow below steps:
Step:1 Click on Launch instance button.
Step:2 Enter a name of instance like Docker.
Step :3 Select Amazon Linux AMI (Amazon Machine Image).
Step: 4 Instance type: t2.micro. (Free trial eligible).
Step:5 Select New key pair. Enter an name: docker pair and click the create key pair.
Step 6: In network settings, Please allow HTTPS and HTTP ports and source type: anywhere
Step 7: Click on Launch Instance.
Here you can seen, our ec2-instace is created.
Now connect ec2-instance via SSH. Copy the public IP address of ec2-instance.
Command: sudo ssh -i <filename>.pem ec2-user@ip
You have need to grant access to the root user and update the system.
Command: sudo su
Command: yum update -y
First you have Install the docker engine on ec2-instance.
Command: yum install docker -y
After install docker engine, check whether docker engine start or not. If not first you must start docker engine.
Command: service docker status
Command: service docker start
Yeah, Successfully docker engine started….
Now, You have created one container and name is “fenilcontainer” and allow the port of this container. So that map port of the container with port of the ec2-instance.
Command: docker run -td — name <container name> -p 80:80 ubuntu
Here, left end side 80 denoted ec2-instance port and right end side 80 denoted container port.
You are suppose to check container details like container id, name etc.
Command: docker ps -a
To check which port you have expose in particular container.
Command: docker port <container name>
Now you have go inside the container.
Command: docker exec -it <container name> /bin/bash
So, here you are in the container and in this container install apache server and start the apache server.
Command: apt-get update
Command: apt-get install apache2
Command: service apache2 start
Now you can copy public IP address of ec2-instance and past the any browser.
You can see the default page of apache server.
If you want to change or add any content of this page then please follow below command.
Command: cd /var/www/html
Command: ls
Command: echo “Welcome, How are you ??…” > index.html
Now refresh the browser and see what happen. Yeah its change it…
After that stop container and delete the container.
That’s it !!
Thank you….