Using Docker for a Simple Website
Make sure you have Docker installed before you begin this activity.
Create a folder named my-website-project.
Set up your website files
Create a folder named public_html inside the my-website-project folder.
Inside the public_html folder, create an index.html file and put this code into it:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello Docker</title>
</head>
<body>
<h1>Hello Docker!</h1>
</body>
</html>
Create a Dockerfile that defines your Docker image
In the my-website-project folder, create a file named Dockerfile (note that the D is captialized, and there is no file extension). Then put this into the file:
FROM httpd:2.4
COPY ./public_html/ /usr/local/apache2/htdocs/
This file will pull an image from DockerHub that has an Apache server running in it. Then it will copy the contents of your public_html folder into the doc root directory of the Apache server.
Build the Image
Run this command to build the image from the docker file:
docker build -t apache2-img .
Create a Container from the Image
Run this command to create/run a container from the image:
docker run -dit --name my-website -p 8080:80 apache2-img
Now you can visit your website by opening a browser and navigating to localhost:8080.