Track 1: Simple Docker
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
Dockerfileto set up the web server.
# Use an official nginx image as the base image
FROM nginx:alpine
# Copy the HTML file to the nginx html directory
COPY static /usr/share/nginx/html/
# Expose port 80
EXPOSE 80
# Start nginx
CMD ["nginx", "-g", "daemon off;"]Build the Docker image:
Save all
Open a terminal, navigate to your project directory, and build the Docker image.
docker build -t nginx-img .Run the Docker container:
Run the container using the image you just built.
docker run -d -p 80:80 nginx-imgThis 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
docker rm -f (docker ps -aq)To verify
docker ps -aqDelete all the Docker images
docker rmi -f (docker images -q)To verify if all images are deleted
docker images -aRun the Docker container:
Delete the
COPYcommand line or append#, save the changes
# Copy the HTML file to the nginx html directory
# COPY static /usr/share/nginx/html/Build the image and run the container again, but this time with
-v
docker build -t nginx-img .docker run -d -p 80:80 -v "$(pwd)/static:/usr/share/nginx/html" nginx-imgLast updated