Skip to content

Instantly share code, notes, and snippets.

@LawAbidingNinja
Last active April 24, 2018 13:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LawAbidingNinja/96ec9894d4777134d6c22a269e6dc644 to your computer and use it in GitHub Desktop.
Save LawAbidingNinja/96ec9894d4777134d6c22a269e6dc644 to your computer and use it in GitHub Desktop.
Instructions for the Docker Hands on section in the Kubernetes Dojo

Prerequisites:

  • Docker is installed and set up on your machine
  • You are connected to the Wi-Fi (ask for details if not)

Building the Image

  • 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 .

Running the image (creating the container):

  • 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!

Publish the image to Docker Hub

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

Additional Reading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment