Getting Started With Docker on Amazon Linux EC2
Step 1: Command for root access.
$ sudo su
Step 2: Update the Amazon Linux instance.
# yum update -y
Step 3: Install the Docker
# yum install docker -y
Step 4: Check the Docker version.
# docker --version
Step 5: Start the docker service.
# service docker start
Step 6: Check docker service status is active or still inactive
# service docker status
Step 7: Search the AmazonLinux Image from Docker Hub
# docker search amazonlinux
Step 8: Now Pull the Docker Image from the DockerHub or you can build yoou own image by using Dockerfile.
# docker pull amazonlinux
Step 9: Check the Images
# docker images
Step 10: Run the container with existence image and expose port 80.
# docker run -td --name webserver -p 80:80 amazonlinux
Step 11: Check whether the port is open or not.
# docker port webserver
Step 12: Execute the Command and you will enter it into the Docker container Terminal.
# docker exec -it
webserver /bin/bash
Step 13: Update the container.
# yum update -y
Step 14: Install the Apache2 web server.
# yum install httpd -y
Step 15: Open the HTML directory to deploy the HTML(index.html) file.
# cd var/www/html
Step 16: Run these commands for configuration.
# /usr/sbin/httpd
# vi /root/.bashrc
--- press "esc key" --> :wq --> "enter key"
Create the index.html file in the HTML directory.
# vi index.html
Example:
HTML
<!DOCTYPE html> < html lang = "en" > < head > < meta charset = "UTF-8" > < meta http-equiv = "X-UA-Compatible" content = "IE=edge" > < meta name = "viewport" content = "width=device-width, initial-scale=1.0" > < style > body{ background-color: seagreen; } h1{ margin-left: 400px; } h2{ margin-left: 350px; } p{ margin-left: 350px; font-size: 20px; } </ style > < title >Web Page Hosting on Docker Container</ title > </ head > < body > < h1 >w3wiki - Web Page Hosting on Docker Container</ h1 >< br > < h2 >Technologies Used - Docker, AWS-EC2, Apache2, Git & Github</ h2 >< br > < p > In this ARTICLE I deploy the static website in docker container using AWS Instance < br > < br > Step :- < br > 1.Launch the EC2 Instance in AWS < br > 2.Install the Docker in Instance < br > 3.Run the container in Docker < br > 4.Configure the Web Server Apache2 in container < br > 5.Deploy the code in web server < br > </ p > </ body > </ html > |
Press "esc key" --> :wq --> "enter key"
Step 17: Copy the IP Address from AWS EC2 Instance.
Step 18: Paste the IP Address in the Browser URL
Now we can see the website is hosted in Docker Container.
Web Page Hosting in Docker Container Using AWS
The operating system (OS) libraries and dependencies required to run the application source code which is not reliant on the underlying operating system (OS) included in the Dockerfile, which is a standardized, executable component. Programmers may design, distribute, launch, run, upgrade, and manage containers using the open-source platform Docker.
Contact Us