Installing Docker is the first step in your journey with containerization. This chapter will guide you through the process of installing Docker on various operating systems, troubleshooting common issues, and verifying your installation.
Before we begin, it's important to understand the different Docker editions available:
- Docker Engine - Community: Free, open-source Docker platform suitable for developers and small teams.
- Docker Engine - Enterprise: Designed for enterprise development and IT teams building, running, and operating business-critical applications at scale.
- Docker Desktop: An easy-to-install application for Mac or Windows environments that includes Docker Engine, Docker CLI client, Docker Compose, Docker Content Trust, Kubernetes, and Credential Helper.
For most users, Docker Engine - Community or Docker Desktop will be sufficient.
Docker runs natively on Linux, making it the ideal platform for Docker containers. There are two main methods to install Docker on Linux: using the convenience script or manual installation for specific distributions.
Docker provides a convenient script that automatically detects your Linux distribution and installs Docker for you. This method is quick and works across many Linux distributions:
-
Run the following command to download and execute the Docker installation script:
wget -qO- https://get.docker.com | sh
-
Once the installation is complete, start the Docker service:
sudo systemctl start docker
-
Enable Docker to start on boot:
sudo systemctl enable docker
This method is ideal for quick setups and testing environments. However, for production environments, you might want to consider the manual installation method for more control over the process.
For more control over the installation process or if you prefer to follow distribution-specific steps, you can manually install Docker. Here are instructions for popular Linux distributions:
Docker runs natively on Linux, making it the ideal platform for Docker containers. Here's how to install Docker on popular Linux distributions:
-
Update your package index:
sudo apt-get update
-
Install prerequisites:
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
-
Add Docker's official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
-
Set up the stable repository:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
-
Update the package index again:
sudo apt-get update
-
Install Docker:
sudo apt-get install docker-ce docker-ce-cli containerd.io
-
Install required packages:
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
-
Add Docker repository:
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
-
Install Docker:
sudo yum install docker-ce docker-ce-cli containerd.io
-
Start and enable Docker:
sudo systemctl start docker sudo systemctl enable docker
For other Linux distributions, refer to the official Docker documentation: https://docs.docker.com/engine/install/
For macOS, the easiest way to install Docker is by using Docker Desktop:
-
Download Docker Desktop for Mac from the official Docker website: https://www.docker.com/products/docker-desktop
-
Double-click the downloaded
.dmg
file and drag the Docker icon to your Applications folder. -
Open Docker from your Applications folder.
-
Follow the on-screen instructions to complete the installation.
For Windows 10 Pro, Enterprise, or Education editions, you can install Docker Desktop:
-
Download Docker Desktop for Windows from the official Docker website: https://www.docker.com/products/docker-desktop
-
Double-click the installer to run it.
-
Follow the installation wizard to complete the installation.
-
Once installed, Docker Desktop will start automatically.
For Windows 10 Home or older versions of Windows, you can use Docker Toolbox, which uses Oracle VirtualBox to run Docker:
-
Download Docker Toolbox from: https://github.com/docker/toolbox/releases
-
Run the installer and follow the installation wizard.
-
Once installed, use the Docker Quickstart Terminal to interact with Docker.
After installing Docker, there are a few steps you should take:
-
Verify the installation:
docker version docker run hello-world
-
Configure Docker to start on boot (Linux only):
sudo systemctl enable docker
-
Add your user to the docker group to run Docker commands without sudo (Linux only):
sudo usermod -aG docker $USER
Note: You'll need to log out and back in for this change to take effect.
It's important to understand the difference between Docker Desktop and Docker Engine:
-
Docker Desktop is a user-friendly application that includes Docker Engine, Docker CLI client, Docker Compose, Docker Content Trust, Kubernetes, and Credential Helper. It's designed for easy installation and use on Mac and Windows.
-
Docker Engine is the core Docker runtime available for Linux systems. It doesn't come with the additional tools included in Docker Desktop but can be installed alongside them separately.
-
Permission denied: If you encounter "permission denied" errors, ensure you've added your user to the docker group or are using sudo.
-
Docker daemon not running: On Linux, try starting the Docker service:
sudo systemctl start docker
-
Conflict with VirtualBox (Windows): Ensure Hyper-V is enabled for Docker Desktop, or use Docker Toolbox if you need to keep using VirtualBox.
-
Insufficient system resources: Docker Desktop requires at least 4GB of RAM. Increase your system's or virtual machine's allocated RAM if needed.
To update Docker:
- On Linux, use your package manager (e.g.,
apt-get upgrade docker-ce
on Ubuntu) - On Mac and Windows, Docker Desktop will notify you of updates automatically
If you need to uninstall Docker:
- On Linux, use your package manager (e.g.,
sudo apt-get purge docker-ce docker-ce-cli containerd.io
on Ubuntu) - On Mac, remove Docker Desktop from the Applications folder
- On Windows, uninstall Docker Desktop from the Control Panel
Installing Docker is generally a straightforward process, but it can vary depending on your operating system. Always refer to the official Docker documentation for the most up-to-date installation instructions for your specific system. With Docker successfully installed, you're now ready to start exploring the world of containerization!