# Topic covered
* Docker Engine vs Docker Desktop
* Try docker on Web
* Docker Installation in Ubuntu
* Docker Installation in Windows
  * Docker Toolbox
  * Docker Desktop
* Docker Installation in Mac
* Post-installation steps for Linux

2.1 Docker installation

# docker version
docker --version
docker -v

# docker packages - version
docker version

docker info

# test
sudo docker run hello-world

On Linux

  • Docker client, Docker daemon and Container runs on the same Host

On Window or MacOSX

  • Docker daemon cannot be run directly on Non-Linux platform natively because it user Linux specific Kernel feature
  • Need to run inside Docker-Machine - Install Docker Desktop
  • Docker client –> docker commands, docker CLI
  • Docker server –> dockerd(docker daemon)

2.1.1 Docker Engine vs Docker Desktop

Docker engine is the layer on which Docker runs. It’s a lightweight runtime and tooling that manages containers, images, builds, and more.

https://docs.docker.com/engine/install/ubuntu/

Docker Desktop provides GUI to manage containers, applications, and images directly from your machine. It includes Docker Engine along with additional features.

Docker Desktop on Linux runs a Virtual Machine (VM) which creates and uses a custom docker context, desktop-linux, on startup.

https://docs.docker.com/desktop/troubleshoot-and-support/faqs/linuxfaqs#why-does-docker-desktop-for-linux-run-a-vm

This means images and containers deployed on the Linux Docker Engine (before installation) are not available in Docker Desktop for Linux.

Commercial use of Docker Desktop in larger enterprises requires a paid subscription.

https://docs.docker.com/desktop/install/linux-install/

2.1.2 Try docker on Web

2.1.3 Docker Installation in Ubuntu

Uninstall old versions

# Uninstall- unofficial packages:
sudo apt-get remove docker docker-engine docker.io

for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done

Installation

Set up Docker’s apt repository

  • These are helper tools needed to securely download and add Docker’s official repository
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

Add the repository to Apt sources:

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update
# Install the Docker packages.
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Verify installation
sudo docker run hello-world

2.1.4 Docker Installation in Windows

Install Docker Toolbox

If you install Docker Toolbox on a Windows machine, the installer automatically installs Oracle Virtualbox to run the Docker virtual machine.

The Docker Toolbox installs everything you need to get started with Docker on Mac OS X and Windows. It includes the Docker client, Compose, Machine, Kitematic, and VirtualBox.

Install Docker Desktop

Windows Subsystem for Linux (WSL) 2 is a full Linux kernel built by Microsoft, which lets Linux distributions run without managing virtual machines. With Docker Desktop running on WSL 2, users can leverage Linux workspaces and avoid maintaining both Linux and Windows build scripts. In addition, WSL 2 provides improvements to file system sharing and boot time.

# Check WSL version
wsl --status

# Change WSL version to WSL2
wsl --set-default-version 2
  • Install Docker Desktop
# Check installation/version
docker -v

2.1.5 Docker Installation in Mac

2.2 Post-installation steps for Linux

Manage Docker as a non-root user

Want to avoid typing sudo for docker command

# Create the docker group.
sudo groupadd docker

# Add your user to the docker group.
sudo usermod -aG docker $USER

# activate the changes to groups
newgrp docker

# Check
docker run hello-world
  • Later
sudo usermod -aG docker ${USER} && su - ${USER} && id -nG
sudo usermod -a -G docker ${USER} 

Configure Docker to start on boot

  • Automatically start Docker and Containerd on boot
sudo systemctl status containerd.service

# Enable
sudo systemctl enable docker.service
sudo systemctl enable containerd.service

# Disable
sudo systemctl disable docker.service
sudo systemctl disable containerd.service

Docker/Container Status

# Check docker status
sudo systemctl status docker

# Stop
sudo systemctl stop docker
sudo service docker stop

# Start
sudo service docker start

# Restart
sudo service docker restart
sudo systemctl restart docker.service