This project demonstrates the containerization of a simple HTML page using Nginx and Docker.
-
Basic HTML Page:
- Create a plain HTML page named
index.html
with some content (e.g., "Hello, Docker!").
- Create a plain HTML page named
-
Nginx Configuration:
- Create an Nginx configuration file named
nginx.conf
that serves theindex.html
page. - Configure Nginx to listen on port 80.
- Create an Nginx configuration file named
-
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.
- Create a
-
Building the Docker Image:
- Build the Docker image using the
Dockerfile
.
- Build the Docker image using the
-
Push the image on ECR
- Make the public repository and push them on the ECR
- index.html: The static HTML page served by the Nginx server.
- nginx.conf: Custom Nginx configuration to serve the
index.html
. - Dockerfile: Defines the Docker image for the project.
- aws configure (provide keys, secret access keys, region and formats)
- aws sts get-caller-identity (to verify the user credentials of AWS)
- Create a Public ECR Repository: aws ecr-public create-repository --repository-name sal-nginx-docker
- Authenticate Docker with ECR – aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws 4.1 Retrieve a token and authenticate with Docker - Linux/Mac: ~/.docker/config.json 4.2 Remove or comment out the "credsStore" or "credHelpers" line. Ensure the file looks like this: { "auths": { "public.ecr.aws": {} } } 4.3 Then Retry the AWS ECR login.
- Once login is successful, run - sudo apt update, sudo apt upgrade -y.
- Restart, enable and check the status of docker if it is running or not.
6.1 docker build -t sal-nginx-docker .
6.2 docker tag sal-nginx-docker:latest public.ecr.aws/975050024946/sal-nginx-docker:latest
6.3 docker images
6.4 docker run -d -p 8082:80 sal-nginx-docker (In browser, URL will work - http://localhost:8081) - as 8080 port was used by my local so ran on 8081 port
6.5 docker push public.ecr.aws/975050024946/sal-nginx-docker:latest
- Once it is pushed successfully, the image will be pushed to the ECR repository.
- PFB sceenrshots from the AWS console for the ECR Registry Folder creation and dockerized image pushed to the folder.