- Docker is installed and set up on your machine
- You are connected to the Wi-Fi (ask for details if not)
- Create a new directory called DockerNginx, this is the staging ground for our new docker image.
- In this directory create a directory called ‘my-website’.
- Within the my-website directory create a file called index.html
- Edit index.html to create a basic static website (template code below). Feel free to customise and edit this page to your heart's content (anything you place in the 'my-website' folder will be made available to nginx):
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>RENAME_ME's Website</title>
</head>
<body>
<h1>Hello, world!</h1>
</body>
</html>
- Back inside the DockerNginx directory create a file called: ‘Dockerfile’ (no extension).
- Open Dockerfile with a text editor and add the following lines:
FROM nginx
COPY my-website /usr/share/nginx/html
- Open the DockerNginx directory in terminal/powershell and run:
docker build -t my-nginx .
docker run --name nginx1 -d -p 8080:80 my-nginx
- Your site should now be up and running locally! Navigate to
localhost:8080
in your web browser to check!
In order to publish the image to Docker Hub:
Take note of your Docker hub username
- In terminal/powershell run:
docker login
- Login using your Docker Hub Credentials
- Run
docker images
this will list the images on your machine, take note of the image id for your my-nginx image. - Run
docker tag MY_IMAGE_ID MY_DOCKERHUB_USERNAME/my-nginx:latest
- Run
docker push MY_DOCKERHUB_USERNAME/my-nginx:latest