The objective of this assignment is to familiarize yourself with Docker and containerization by Dockerizing a simple HTML page using Nginx as the web server.
Install docker in ubuntu machine
sudo apt install docker.io -y
-
Basic HTML Page:
- Create a plain HTML page named
index.html
with some content (e.g., "Hello, Docker!").
- Create a plain HTML page named
#------------------index.html---------------------------------
<!DOCTYPE html>
<html>
<head>
<title>Hello, Docker!</title>
</head>
<body>
<h1>Hello, Docker!</h1>
<p>This is a plain HTML page served by Nginx in a Docker container.</p>
</body>
</html>
#-------------------------------------------------------------------
-
Nginx Configuration:
-
Create an Nginx configuration file named
nginx.conf
that serves theindex.html
page. -
Configure Nginx to listen on port 80.
-
#-----------------------------nginx.conf-------------------------
events {}
http {
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html;
}
}
}
#----------------------------------------------------------------
-
Dockerfile:
-
Create a
Dockerfile
to define the Docker image. -
Use an official Nginx base image.
-
Copy the
index.html
andnginx.conf
files into the appropriate location in the container. -
Ensure that the Nginx server is started when the container is run.
-
#---------------------------Dockerfile----------------------
FROM nginx:latest
COPY index.html /usr/share/nginx/html/index.html
COPY nginx.conf /etc/nginx/nginx.conf
#-----------------------------------------------------------
-
Building the Docker Image:
- Build the Docker image using the
Dockerfile
.
- Build the Docker image using the
docker build -t custom_webserver:v1 -f dockerfile .
Lets! Test the image
docker run -it -d -p 8080:80 custom_webserver:v1
Its working fine WOW!
-
Push the image on ECR
- Make the public repository and push them on the ECR
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
apt install unzip
unzip awscliv2.zip
sudo ./aws/install
aws --version
aws configure
AWS Access Key ID:
AWS secret Acess Key:
Default region name: ap-south-1
Default output format:
https://gallery.ecr.aws/c3w1m1q2/docker_customwebservice_adarsh