Docker Basic: Part II

Docker Basic: Part II

Creating Own Image in Docker

To create a Docker container that serves your index.html file, you can use a simple web server like Nginx. Here’s how to build and run it using Docker. Make a folder and create a file named: index.html

mkdir digital_banking
cd digital_banking

Create a index.html File: Save the provided HTML code into an index.html file in your project directory.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Digital Banking Department - Coming Soon</title>
    <style>
        body, html {
            margin: 0;
            padding: 0;
            height: 100%;
            font-family: Arial, sans-serif;
        }

        .coming-soon-container {
            display: flex;
            align-items: center;
            justify-content: center;
            height: 100%;
            background-color: #00753a;
            color: #7e1418;
            text-align: center;
        }

        .content {
            max-width: 600px;
            padding: 20px;
        }

        h1 {
            font-size: 3em;
            margin: 0 0 20px;
        }

        p {
            font-size: 1.5em;
            margin: 0;
        }
    </style>
</head>
<body>
    <div class="coming-soon-container">
        <div class="content">
            <h1>Digital Banking Department</h1>
            <p>Our new web portal is coming soon. Stay tuned!</p>
        </div>
    </div>
</body>
</html>

Create a Dockerfile: Create a file named Dockerfile in the same directory with the following content:

FROM nginx:1.27-alpine
COPY ../ /usr/share/nginx/html
EXPOSE 80

Build/Run the Docker Image: Run the following command to build your Docker image. Replace digital_banking with your desired image name.

docker login
docker build -t digital_banking .

Run the Docker Container: Once the image is built, run a container using the following command:

docker run -v <directory path of index.html>:/usr/share/nginx/html:ro -p 8082:80 -d <docker_image_name>
docker run -v C:\Users\abliv\Desktop\digital_banking\:/usr/share/nginx/html:ro -p 8082:80 -d digital_banking

This command maps port 8082 on your local machine to port 80 in the container, which is where Nginx serves content by default.

Access Your “Coming Soon” Page: Open a web browser and navigate to http://localhost:8082 to see your “Coming Soon” page.