Docker Installation on MacOS, Linux and Windows

This is blog series on Docker we will start with Docker installation on all the Machines . i.e. macOS, Linux and Windows. Also along with the installation, we will focus on all the possible issues which you can encounter during the pre-installation as well as post-installation.

Table of Content

  1. Installation of Docker on MacOS
  2. Installation of Docker on Windows
  3. Installation of Docker on Linux
  4. Troubleshooting Docker Installation
  5. Conclusion

1. Installation of Docker on macOS

With the introduction of Apple's new Silicon chip, you need to choose the correct Docker Desktop dmg package for the installation of Docker Desktop. Here is the official documentation of Docker for macOS. Here are the links for downloading the correct package based on your MacBook Chip -

  1. Intel Chip- Click here to download
  2. Silicon Chip- Click here to download

(For Apple silicon Chip it is recommended to install rosetta $softwareupdate --install-rosetta)

1.1 Pre-requisites for Intel chip Docker desktop

  1. Memory- You must have at least 4 GB of RAM
  2. MacOS- macOS version should be 10.15 or higher, docker desktop installation is supported on macOS Catalina, Big Sur and Monterey.
  3. VirtualBox 4.3.30 not supported - You must upgrade the virtual box installation

1.2 Unpack Docker.dmg

After downloading the Docker.dmg you can unpack it by double-clicking on it.

Unpack Docker.dmg

1.3 Move the Docker.app to applications directory

Later it will ask to move the Docker app to the Applications directory, so simply drag and move the Docker app to applications directory.

Move docker app to Applications

1.4 Start Docker Desktop

From the Applications directory, you can start the Docker Desktop by double-clicking on it. You should see the following page on the docker start up -

Docker startup page

The default docker start-up shows the total number of docker images that you are using or have pulled from the docker hub. Docker is free for Personal Usage or it will be free for Small organizations but for business purposes, you have to purchase the business subscription.

1.5 Troubleshooting docker startup error - Cannot connect to the Docker daemon

If your Docker desktop app is not running then you might face the error "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?."

Fix- Please check the Docker Desktop service, most likely your Docker service is not up.

(For detailed troubleshooting refer to - How to fix Error starting docker service Unit not found?)

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running

1.6 Install Docker desktop from command line

If you do not want to install the Docker desktop by downloading dmg package then there is one good alternative to install it from the command line.

But you need root permission to install the docker from the command line. Use the following command from terminal for installing the docker from the command line -

1sudo hdiutil attach Docker.dmg
2
3sudo /Volumes/Docker/Docker.app/Contents/MacOS/install
4
5sudo hdiutil detach /Volumes/Docker

While installing from the command line you need to supply the following inputs -

  1. --accept-license - You need to agree to the docker Subscription service agreement for using the docker
  2. --allowed-org= - You need to provide the organization name where you are going to use the docker


2. Installation of Docker on Windows

Docker provides an installation executable for Windows and it can be downloaded from here.

2.1 Pre-requisites

You should meet the following pre-requisites for installing docker on windows -

  1. OS- You should use Windows 11 64-Bit Pro version 21H2 or Higher or Windows 10 64-bit: Pro 21H1
  2. Hyper-V Hyper-V and containers features must be enabled
  3. Memory and CPU- 4GB of RAM and 64 Bit processor with Second Level Address Translation (SLAT)
  4. Virtualization Enabled- You must enable the virtualization from the BIOS

2.2 How to install Docker Desktop

There are a couple of ways to install the Docker Desktop on Windows Install Interactively or Install from the command line. Let's take a look at both the installations -

Install Interactively

  1. Download & Install- First download the Docker desktop exe from here, after downloading the Docker desktop exe you can double click on it to begin the installation.
  2. Select WSL 2 or Hyper-V- During the installation it will prompt for WSL2 or Hyper-V, make sure to select WSL 2 or in the other case if you only have one option then you will not be able to switch the backend.
  3. Add other users to Docker-Group- Interactive installation of docker is generally easy to follow. After the successful installation of docker if other users are belonging to the system then make sure to add all Local Users and Groups to the docker group. It can be done by going to Computer Management->Local Users and Groups->Groups->docker-users

Install From command line

Even though if you are using the command line but you still need to download the docker executable to perform the docker installation via command line.

Use the following installation command based on your preference but make sure you are on the correct path in which Docker executable exists -

Terminal

1"Docker Desktop Installer.exe" install 

Powershell

1Start-Process '.\win\build\Docker Desktop Installer.exe' -Wait install

Windows Command Prompt

1start /w "" "Docker Desktop Installer.exe" install

During the installation from the command line, it might ask for the following inputs -

  1. --quiet - Suppress installation information logs during the installation process
  2. --accept-license - You need to agree to the docker Subscription service agreement for using the docker
  3. --allowed-org= - You need to provide the organization name where you are going to use the docker
  4. --backend= - Choose the backend with which you wanna go with hyper-v ot wsl-2

2.3 Start Docker Desktop on Windows

You can start the Docker desktop from the start prompt. Click on the start prompt and search for Docker Desktop and click on the Docker Desktop icon to start it.

Starting up Docker desktop on windows

After starting the docker desktop it will ask you to accept the license and agreement for its use.


3. Installation of Docker on Linux

Docker offers two installer packages DEB and RPM for the Linux operating system. DEB packages can be installed on Debian as well as Ubuntu but for Fedora you must use RPM package.

There is one more distribution Arch Linux but you can not use DEB or RPM packages and you must follow these instructions are specifically for Arch Linux.

3.1 Pre-requisites

  1. CPU- Virtualization should be supported by the CPU and have 64-bit kernel.
  2. Memory- 4GB of RAM
  3. KVM- KVM virtualization support should be there.
  4. QEMU- The QEMU must be 5.3 or newer.
  5. Desktop Environment- For Linux you must either use GNOME or KDE Development environment.

3.2 Verify the KVM Support

With the latest versions of Docker, it is mandatory to have KVM virtualization support enabled, so before you proceed with the installation you must load the KVM -

  1. Load the KVM manually
1modprobe kvm 
  1. Based on the type of processor choose the suitable command to load the module -
1modprobe kvm_intel # Intel based CPU  
2
3modprobe kvm_amd  # AMD based CPU
  1. Verify the KVM status and also verify if KVM modules are enabled -
1kvm-ok 
1lsmod | grep kvm
  1. KVM device user permission
1 ls -al /dev/kvm  

and also add a user to the KVM group -

1sudo usermod -aG kvm $USER

3.3 Install Docker Desktop on Debian and Ubuntu

Before installing Docker Desktop on Debian or Ubuntu-based operating system you must add the docker repository to apt manager.

  1. Update the apt repository
1sudo apt-get update
  1. Install the ca-certificates
1sudo apt-get install \
2    ca-certificates \
3    curl \
4    gnupg \
5    lsb-release
  1. Add Docker's official GPG key
1sudo mkdir -p /etc/apt/keyrings
2
3curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg 
  1. Run the following command to set the docker repository
1echo \
2  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
3  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  1. Install Docker Engine - Now we need to install the latest version of Docker Engine, containerd, and Docker Compose
1sudo apt-get update
2
3sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
4 
  1. Verify the docker engine installation
1sudo docker run hello-world 

3.4 Install Docker on Fedora(rpm)

Before you install Docker on RPM based Fedora operating system you must check the version of Fedora and it should be Fedore 34 or higher.

  1. Add docker repository to dnf package manager -
1sudo dnf -y install dnf-plugins-core
2
3sudo dnf config-manager \
4    --add-repo \
5    https://download.docker.com/linux/fedora/docker-ce.repo 
  1. Install the latest docker-engine -
1sudo dnf install docker-ce docker-ce-cli containerd.io docker-compose-plugin  
  1. For installing a specific version of Docker use the following command find the needed version of Docker -
1dnf list docker-ce  --showduplicates | sort -r 

Copy the desired version from the output of the above command and update it in the following installation command of docker -

1 sudo dnf -y install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io docker-compose-plugin 
  1. Verify the Docker by running a Hello World docker image -
1sudo systemctl start docker 

Hello world docker image -

1 sudo docker run hello-world 

4. Troubleshooting Docker Installation

4.1 Cannot start docker after installation on Windows

There might some instances where you have installed VirtualBox along with the Hyper-V onto your windows machine. Hyper-V and VirtualBox do not go well with Docker installation and you might end up with the following error message -

1Running pre-create checks...
2Error with pre-create check: "Hyper-V is installed. VirtualBox won't boot a 64bits VM when Hyper-V is activated. It is installed but deactivated, you can use --virtualbox-no-vtx-check to try anyways"
3Look like something went wrong in step 'Checking if machine default exists'...
4Press any key to continue... 

Possible Solutions*

Solution-1

  1. You can either uninstall Hyper-V or disabled it by running
1bcdedit /set hypervisorlaunchtype off 
  1. Create docker machine using -
1docker-machine create -d virtualbox --virtualbox-no-vtx-check test

Solution-2

Docker does support Hyper-V as a driver, so in case you are interested in using Hyper-V then refer to the following steps

  1. Enable/create virtual switch referring to the official documentation form microsoft. Also, make sure that you click the check box Open Control Panel -> System and Security -> Programs -> Turn Windows features on or off -> Check the Hyper-V box
  2. Now after that create docker-machine using the network switch and Hyper-Driver.
1docker-machine create -d hyperv --hyperv-virtual-switch "name of the virtual switch created above" default

4.2 How to change the docker image installation directory?

During the docker installation, you might want to set a custom docker image location. There are a couple of ways by which you can set the docker image installation directory path -

1. Create 'docker.service.d' and update 'docker-storage.conf'(This approach does not require a restart)

Create a directory names docker.service.d under /etc/systemd/system/

1sudo mkdir -p /etc/systemd/system/docker.service.d 

Create a file docker-storage.conf inside the directory docker.service.d

1sudo $EDITOR /etc/systemd/system/docker.service.d/docker-storage.conf

If you are using a docker version 17.06-ce or older then put the following configuration inside the docker.service.d

1[Service]
2ExecStart=
3ExecStart=/usr/bin/docker daemon -H fd:// --graph="/mnt"

For docker version 17.06-ce or higher use the following configuration -

1[Service]
2ExecStart=
3ExecStart=/usr/bin/dockerd -H fd:// --data-root="/mnt"

This approach would not require any kind of docker service restart.


2. Update 'daemon.json' (You need to restart the docker service)

You could also set the docker image installation path by updating the daemon.json file located at /etc/docker/daemon.json. But after updating the file you need to restart the docker service.

Use the following configuration for setting up the path_(Please update the path as per your requirement)_

1{
2    "graph": "/image/mount/location",
3    "storage-driver": "overlay"
4} 

Restart the docker server -

1sudo systemctl daemon-reload
2sudo systemctl restart docker

5. Conclusion

Hope this article will help you for installing the docker based on the operating system of your choice. Although the docker installation and initial setup might be different but the other operations and docker commands work the same irrespective of the base operating system.

References-

StackOverflow - https://stackoverflow.com/questions/24309526/how-to-change-the-docker-image-installation-directory Docker - https://docs.docker.com/desktop/

Posts in this Series