×


Process to install Docker on Windows

Docker Desktop for Windows is the Community version of Docker for Microsoft Windows.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform Docker related tasks.
In this context, we shall look into the steps to install Docker on Windows.


How to install Docker on Windows ?

Docker requires a Linux kernel to run Linux Containers. To install Docker on windows, we need to set up a Linux virtual machine to run as a guest in Windows 10 Home.
We can perform the Linux VM set up manually using the Docker machine. Docker machine is a CLI tool for installing Docker Engine on virtual hosts.
This Docker Linux VM can either run on the local system or on a remote server. Docker client will use SSH to communicate with Docker Engine. Docker Engine runs on top of the Linux Kernel and helps in building/running containers.
Whenever we create and run images, the actual process will happen within the VM, not on the host (Windows).

Initial Setup to install Docker on Windows

The initial setup involve installing a few additional software. Also, we need to make sure that we are using the latest stable version of Windows.

The additional software to be installed includes:
i. Install Git Bash for Windows. This will be our primary terminal for running Docker commands.
ii. Install Chocolatey, a package manager for Windows. It will make the work of installing the rest of the programs easier.
iii. Install VirtualBox and its extension. Alternatively, after installing Chocolatey, we can simply execute this command inside an elevated PowerShell terminal:

C:\ choco install virtualbox

iv. To run Docker inside the WSL2 environment, we need to set up WSL2 first.

How to use Docker Engine Setup to install docker on Windows ?

Here, we will follow the steps below to install Docker Engine. First, we need to install Docker Machine.

1. Install Docker Machine by executing the command inside an elevated PowerShell terminal.

C:\ choco install docker-machine

2. Using Git Bash terminal, use Docker Machine to install Docker Engine. This will download a Linux image containing the Docker Engine and have it run as a VM using VirtualBox. Simply execute the following command:

$ docker-machine create –driver virtualbox default

3. Next, we need to configure which ports are exposed when running Docker containers. Doing this will allow us to access our applications via localhost<:port>.

To do this, we need to launch Oracle VM VirtualBox from the start menu. Select default VM on the side menu. Next click on "Settings > Network > Adapter 1 > Port Forwarding". We should find the ssh forwarding port that is already set up.
4. Next, we need to allow Docker to mount volumes located on the hard drive. By default, we can only mount from the C://Users/ directory. To add a different path, simply go to Oracle VM VirtualBox GUI. Select default VM and go to "Settings > Shared Folders". Add a new one by clicking the plus symbol. Enter the fields like so. If there’s an option called Permanent, enable it.
5. To get rid of the invalid settings error, simply increase Video Memory under the Display tab in the settings option. Video memory is not important in this case, as we will run the VM in headless mode.
6. To start the Linux VM, simply execute this command in Git Bash. The Linux VM will launch. Give it some time for the boot process to complete. It should not take more than a minute. We will need to do this every time after the host OS boot:

$ docker-machine start vbox

7. Next, we need to set up our Docker environment variables. This is to allow the Docker client and Docker Compose to communicate with the Docker Engine running in the Linux VM, default. Let us look at the steps to set up Docker environment variables.

How to Setup Docker environment variables ?

To do this, simply execute the following commands in Git Bash:

# Print out docker machine instance settings
$ docker-machine env default# Set environment variables using Linux 'export' command
$ eval $(docker-machine env default --shell linux)

We need to set the environment variables every time we start a new Git Bash terminal. To avoid this, we can copy eval output and save it in the .bashrc file.
It should look something like this:

export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.101:2376"
export DOCKER_CERT_PATH="C:\Users\Michael Wanyoike\.docker\machine\machines\default"
export DOCKER_MACHINE_NAME="default"
export COMPOSE_CONVERT_WINDOWS_PATHS="true"For the DOCKER_CERT_PATH

We need to change the Linux file path to a Windows path format. Also, take note that there is a chance the IP address assigned might be different from the saved one every time we start the default VM.

How to use Docker Tools to Set up Docker ?

Here, we need to install the following tools using PowerShell in admin mode. These tools are packaged inside the Docker for Windows installer. Since the installer refuses to run on Windows 10 Home, we will install these programs individually using Chocolatey:

C:\ choco install docker-cli
C:\ choco install docker-compose

Once the installation process is complete, we can switch back to Git Bash terminal. It is better to execute commands in Linux syntax. Let us execute the following commands to ensure Docker is running:

# Start Docker VM
$ docker-machine start default
# Confirm Docker VM is running
$ docker-machine ls

# Configure Docker Envrionment to use Docker Vm
$ eval $(docker-machine env default --shell linux)

# Confirm Docker is connected. Should output Docker VM specs
$ docker info

# Run hello-world docker image. Should output "Hello from Docker"
$ docker run hello-world

If all the above commands run successfully, it means we have successfully installed Docker.
For hot module reloading to work from a Docker Container in Windows requires the following:
i. When using parcel, specify HMR port in the package.json start script:

parcel src/index.html –hmr-port 1235

ii. In the VM’s Port Forwarding rules, make sure these ports are exposed to the host system:

1234
1235

iii. inotify does not work on vboxsf filesystems, so file changes can’t be detected. The workaround is to set polling for Chokidar via environment variables in docker-compose.yml.

Here's the full file so that we can see how it's set:

version: '3'
services:
dev:
image: node:10-jessie-slim
volumes:
- nodemodules:/usr/src/app/node_modules
- ./:/usr/src/app
working_dir: /usr/src/app
command: npm start
ports:
- 1234:1234
- 1235:1235
environment:
- CHOKIDAR_USEPOLLING=1
volumes:
nodemodules:
external: true

Now that we have a fully working implementation of Docker on Windows 10 home, let us set it up on WSL2 for those who are interested.

How to set up Windows Subsystem for Linux 2 ?

Installing Docker on WSL2 is not as straightforward as it seems. Unfortunately, the latest version of the Docker Engine can't run on WSL2. However, there’s an older version, docker-ce=17.09.0~ce-0~ubuntu, that is capable of running well in WSL2. Let us see how to access Docker Engine running in the VM we set up earlier from a WSL terminal.
All we have to do is install Docker client and Docker compose.

On WSL2 Ubuntu Terminal, execute the following:
i. Install Docker using the official instructions:
# Update the apt package list.

sudo apt-get update -y

# Install Docker's package dependencies.

sudo apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common

# Download and add Docker's official public PGP key.

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# Verify the fingerprint.

sudo apt-key fingerprint 0EBFCD88

# Add the `stable` channel's Docker upstream repository.
#
# If we want to live on the edge, we can change "stable" below to "test" or
# "nightly". I highly recommend sticking with stable!

sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"

# Update the apt package list (for the new apt repo).

sudo apt-get update -y

# Install the latest version of Docker CE.

sudo apt-get install -y docker-ce

# Allow the user to access the Docker CLI without needing root access.

sudo usermod -aG docker $USER

ii. Install Docker Compose using PIP, which will simply install the latest stable version:
# Install Python and PIP.

sudo apt-get install -y python python-pip

# Install Docker Compose into the user's home directory.

pip install --user docker-compose

iii. Fix the Docker mounting issue in WSL terminal by inserting this content in /etc/wsl.conf. Create the file if it does not exist:

[automount]
root = /
options = "metdata"

Restart the machine for this setting to take effect.


iv. Assuming that Linux Docker VM is running, we will need to connect the Docker tools in the WSL environment to it. If we can access docker-machine from the Ubuntu terminal, we can run the eval command. Otherwise, insert the following Docker variable in the .bashrc file. We need to restart the terminal or execute source ~/.bashrc for the settings to take effect. Running Docker commands should work properly in WSL without a hitch.

[Need urgent assistance to install Docker on Windows? – We're available 24*7. ]


Conclusion

This article will guide you on the steps to install docker on Windows by setting up a Linux virtual #machine to run as a guest in Windows 10 Home.
Docker Desktop is an easy-to-install application for your #Mac or Windows environment that enables you to build and share containerized applications and microservices. Docker Desktop includes Docker #Engine, Docker CLI client, Docker Compose, Notary, #Kubernetes, and Credential Helper.
You can download #Docker #Desktop for Windows from Docker Hub. This relates to installing Docker Desktop on #Windows 10 Pro, Enterprise, and Education.