Description: Create a Docker container that runs a basic web server using Nginx.
Technologies: Docker, Nginx
Learning Outcomes: Understand how to create and run containers, expose ports, and serve static content.
Procedure
Create the HTML file:
First, create a directory for your project and navigate into it.
Create a folder called static
Get static webpages from the Internet
Visit https://html5up.net/ to choose for site templates
Copy all the content from .zip and paste it to static
Create a Dockerfile:
In the same directory, create a filename called Dockerfile to set up the web server.
# Use an official nginx image as the base imageFROM nginx:alpine# Copy the HTML file to the nginx html directoryCOPY static /usr/share/nginx/html/# Expose port 80EXPOSE 80# Start nginxCMD ["nginx", "-g", "daemon off;"]
Build the Docker image:
Save all
Open a terminal, navigate to your project directory, and build the Docker image.
Run the Docker container:
Run the container using the image you just built.
This will start a simple static web server with your contact information and address. You can access it by navigating to http://localhost in your web browser.
Delete all Container & Images
Delete all the Docker container
To verify
Delete all the Docker images
To verify if all images are deleted
Run the Docker container:
Delete the COPY command line or append #, save the changes
Build the image and run the container again, but this time with -v