[Docker] Installing Docker

Explore our prominent projects, including

Installing Docker

In this chapter, we'll walk through setting up a Docker development environment on most modern desktop operating systems. First, we'll install the Docker client on your native development platform. Then, we'll get a Docker server up and running on Linux. Finally, we'll test the installation to ensure everything works smoothly.

Keep in mind that while the Docker client can run on Windows and macOS to control a Docker server, Linux containers can only be built and launched on a Linux system. For non-Linux systems, you'll need a virtual machine or remote server to host the Linux-based Docker server. Docker Community Edition, Docker Desktop, and Vagrant provide solutions for this issue, which we'll discuss later in this chapter. However, note that the focus of this book primarily lies on Linux containers.

Docker Client

The Docker client supports 64-bit versions of Linux, Windows, and macOS.

On Linux, popular distributions like Debian, Red Hat, and Alpine Linux are supported. Debian systems use the deb package format and apt for package management, while Red Hat systems rely on RPM Package Manager (rpm) files and tools like yum or dnf. Alpine Linux utilizes the Alpine Package Keeper (apk) for managing software packages.

For macOS and Windows, GUI installers provide the easiest method to install Docker. Homebrew for macOS and Chocolatey for Windows are also popular options among technical users.

Installing Docker on Linux

It's recommended to run Docker on a recent release of your preferred Linux distribution for stability. Ubuntu or Fedora are suggested options. Below are instructions for Ubuntu Linux 22.04 and Fedora Linux 36:

Ubuntu Linux 22.04 (64-bit)

Ensure no older Docker versions are installed:

$ sudo apt-get remove docker docker.io containerd runc
$ sudo apt-get remove docker-engine

Add required software dependencies and Docker repository:

$ sudo apt-get update
$ sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
$ sudo mkdir -p /etc/apt/keyrings
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg |\
    sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
$ sudo chmod a+r /etc/apt/keyrings/docker.gpg
$ echo \
    "deb [arch=$(dpkg --print-architecture) \
    signed-by=/etc/apt/keyrings/docker.gpg] \
    https://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) stable" |\
    sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install Docker:

$ sudo apt-get update
$ sudo apt-get install \
    docker-ce \
    docker-ce-cli \
    containerd.io \
    docker-compose-plugin

Fedora Linux 36 (64-bit)

Remove older Docker versions:

$ sudo dnf remove -y \
    docker \
    docker-client \
    docker-client-latest \
    docker-common \
    docker-latest \
    docker-latest-logrotate \
    docker-logrotate \
    docker-selinux \
    docker-engine-selinux \
    docker-engine

Add required software dependencies and Docker repository:

$ sudo dnf -y install dnf-plugins-core
$ sudo dnf config-manager \
    --add-repo \
    https://download.docker.com/linux/fedora/docker-ce.repo

Install Docker:

$ sudo dnf install -y \
    docker-ce \
    docker-ce-cli \
    containerd.io \
    docker-compose-plugin

Installing Docker on macOS and Windows 11

On macOS, use the official Docker Desktop installer. For Windows 11, install Docker Desktop and ensure Windows Subsystem for Linux (WSL2) is set up.

Docker Server

The Docker server is a separate binary used to manage Docker operations. Docker Desktop and Docker Community Edition set up the server automatically. On Linux, start the server using systemctl commands.

Non-Linux VM-Based Server

For Docker workflows on Windows or macOS, you'll need a VM to set up a Docker server. Docker Desktop handles this for you. Alternatively, use Vagrant to create and manage a Docker server Linux VM.

Testing the Setup

Once Docker is installed, test the setup by launching containers based on Ubuntu, Fedora, and Alpine Linux images. Ensure the Docker client can communicate with the Docker daemon properly.

Exploring the Docker Server

While Docker Desktop and Docker Community Edition manage the Docker server for you, it's useful to understand how to start the Docker daemon manually on Linux systems. You can explore the Docker server configuration and underlying host using privileged containers.

Conclusion

Now that Docker is set up, you can delve deeper into managing Docker images and containers. In the next chapter, we'll explore building and managing Docker images, laying the groundwork for container management. Remember to configure Docker appropriately for your environment using Docker contexts, environment variables, or command-line flags.


#Docker