Docker for Windows Beginner Guide

tong eric
Bina Nusantara IT Division
6 min readDec 30, 2022

A simple guide for those starting to learn about Docker

Photo by Rubaitul Azad on Unsplash

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure to deliver software quickly. With Docker, you can manage your infrastructure in the same ways you organize your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.

This tutorial will teach you how to implement Docker on a Windows server.

System Requirement

The following are system requirements for the Docker Windows server which uses WSL :

  • Windows 10 64-bit: Home or Pro 2004 (build 19041) or higher, or Enterprise or Education 1909 (build 18363) or higher.
  • Enable the WSL 2 feature on Windows. For detailed instructions, refer to the Microsoft documentation.

The following hardware prerequisites are required to successfully run WSL 2 on Windows 10:

Installation of Docker Windows

Let's start with installation, First, download the installer for Docker Desktops with this link or you can find the latest version of the installer by visiting this website Link Here.

Click the Get Docker button to start downloading the Docker Desktop installer.

The Docker Desktop installation includes Docker Engine, Docker CLI client, Docker Compose, Docker Content Trust, Kubernetes, and Credential Helper.

Containers and images created with Docker Desktop are shared between all user accounts on the machines where it is installed. This is because all Windows accounts use the same VM to build and run containers. Note that it is not possible to share containers and images between user accounts when using the Docker Desktop WSL 2 backend.

After that, double-click on Docker Desktop Installer.exe to run the installer.

When prompted, ensure the Enable Hyper-V Windows Features or the Install required Windows components for WSL 2 option is selected on the Configuration page.

Follow the instructions on the installation wizard to authorize the installer and proceed with the installation.

When the installation is successful, click Close to complete the installation process.

If your admin account is different from your user account, you must add the user to the docker-users group. Run Computer Management as an administrator and navigate to Local Users and Groups > Groups > docker-users. Right-click to add the user to the group. Log out and log back in for the changes to take effect.

When the installation finishes, Docker starts automatically. The whale in the notification area indicates that Docker is running, and accessible from a terminal.

You can check for the installation is complete or not from the command above :

  1. Run the docker version to check the version.
  2. Run docker run hello-world to verify that your Docker installation was successful.

For Docker Windows, you will need an account from Docker Hub to pull images.

Go to Docker Hub and then register your account by clicking the Signup button on this page. Remember your Docker ID cause you will need it to log in to your account.

You can log in to your account by opening the Docker Desktop application.

Click on the Sign in button on top of the application and then input your Docker ID and passwords.

Tutorial for Docker Windows

Here I will give an example of how to host static websites using official Nginx images from the docker hub.

First, pull the Nginx images to local, you can do it via command prompt with the command below

Docker pull nginx

After that, check on your Docker Desktop. It should have a new image name Nginx in your local repository.

After that, create a folder that will be your workspace. Open it up using your favorite code editor (for example, Visual studio code).

Let’s start by creating an index.html for our static website. Create a new file in this folder and name it index.html.

Copy the HTML below to be contained inside it

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Docker Nginx</title>
</head>
<body>
<h2>Hello from Nginx container</h2>
</body>
</html>

You can make your own modification as long as it is still a static web.

Then we create a file named DockerFile to this folder.

A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Docker can build images automatically by reading the instructions from a DockerFile.

Copy the command below as our Dockerfile command.

FROM nginx:latest
COPY ./index.html /usr/share/nginx/html/index.html

This command simply copies and index.html from the Docker container. You start building our custom image by using a base image. On line 1, you can see we do this using the FROM command. This will pull the nginx:latest image to our local machine and then build our custom image on top of it.

Next, we COPY our index.html file into the /usr/share/nginx/html directory inside the container overwriting the default index.html file provided by nginx:latest image.

After you finish all preparation, you can run this command to build our image

docker build -t <image name> .

Note: Remember to run this command when your command prompt directory is the same as your DockerFile location.

After that, you can check your build image from Docker Desktop. To run this image as a container, you can use the command below in the command prompt :

docker run -it --rm -p 8080:80 --name <container name> <image name>

Docker run for running image, -it is for interactive mode, — rm for stopping removing any container with the same name as it. -p 8080:80 is used to redirect our local machine port 8080 to docker container port 80 and last — name <container name> <image name> to specify which image we want to run.

After that, go to your browser and navigate to http://localhost:8080 to make sure our Html page is being served correctly.

Summary

From this tutorial, we learn about

  1. Installation requirement and process for Docker windows
  2. Basic use of Docker command

--

--