Docker Installation (Windows, macOS, Linux)
Docker is a powerful tool that can be installed on various operating systems, including Windows, macOS, and Linux. In this section, we will walk through the installation process for each of these platforms, making sure you have everything you need to get started with Docker.
1. Docker Installation on Windows
Docker can be installed on Windows using Docker Desktop, which provides a graphical user interface and simplifies the process of managing Docker containers.
Prerequisites for Windows:
- Windows 10/11 Pro or Enterprise (Windows Home can use Docker Desktop with WSL 2)
- Windows Subsystem for Linux (WSL 2): Docker Desktop uses WSL 2 for the Linux kernel on Windows.
- Hyper-V and Containers Features: These need to be enabled in the system BIOS.
Steps to Install Docker on Windows:
-
Download Docker Desktop for Windows:
- Go to the official Docker website and download Docker Desktop for Windows.
-
Install Docker Desktop:
- Run the downloaded installer and follow the installation instructions.
- The installer will enable Hyper-V and WSL 2 features automatically if they are not already enabled.
-
Install WSL 2 (if not already installed):
- Docker Desktop requires WSL 2 to run Linux containers on Windows. If you don’t have WSL 2 installed, Docker will prompt you to install it.
- To install WSL 2, follow the instructions from Microsoft’s WSL installation guide.
-
Launch Docker Desktop:
- Once installed, launch Docker Desktop from the Start menu.
- The first time you run Docker, it will configure Docker Desktop to use WSL 2.
-
Verify Installation:
- Open a command prompt or PowerShell window and type:
docker --version
- You should see the installed Docker version printed on the screen.
-
Test Docker:
- Run the following command to ensure Docker is running correctly:
docker run hello-world
- Docker will download a test image and run a container that outputs a confirmation message if everything is set up properly.
2. Docker Installation on macOS
Docker can also be installed on macOS using Docker Desktop for macOS. This provides an easy way to run Docker containers with the macOS graphical interface.
Prerequisites for macOS:
- macOS 10.14 or later (Mojave, Catalina, Big Sur, or Monterey)
- Virtualization Support: Docker Desktop uses Hypervisor.framework for virtualization on macOS.
Steps to Install Docker on macOS:
-
Download Docker Desktop for macOS:
- Visit the Docker Desktop for macOS page and download the latest version.
-
Install Docker Desktop:
- Open the
.dmg
file you downloaded and drag the Docker application to your Applications folder.
- Open the
-
Launch Docker Desktop:
- Go to the Applications folder and open Docker.
- On the first launch, Docker Desktop will ask for system permissions to install helper tools. Grant the required permissions.
-
Verify Installation:
- Open a terminal and type the following command:
docker --version
- This should display the installed Docker version.
-
Test Docker:
- Run the following command to check that Docker is working correctly:
docker run hello-world
- Docker will pull the "hello-world" image and run it in a container, printing a confirmation message.
3. Docker Installation on Linux
Docker can be installed on various Linux distributions, including Ubuntu, CentOS, and Debian. In this section, we will focus on installing Docker on Ubuntu. The process is similar for other Linux distributions, with minor differences in package management.
Prerequisites for Ubuntu:
- A 64-bit version of Ubuntu (16.04 or later)
- Sudo or root access
Steps to Install Docker on Ubuntu:
- Update Your System: Open a terminal and run the following commands to update your system:
sudo apt update
sudo apt upgrade
-
Install Required Dependencies:
Docker requires some dependencies like
apt-transport-https
,ca-certificates
,curl
,software-properties-common
. Install them using:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
- Add Docker’s Official GPG Key: Run the following command to add Docker's official GPG key, which ensures the authenticity of the Docker packages.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- Add Docker’s Repository: Add the Docker repository to your list of sources so that you can install Docker from it:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- Install Docker Engine: Now, update your package database again and install Docker:
sudo apt update
sudo apt install docker-ce
- Start and Enable Docker: Enable Docker to start automatically when the system boots and start the Docker service:
sudo systemctl enable docker
sudo systemctl start docker
- Verify Installation: To check if Docker is installed and running correctly, use:
docker --version
- Test Docker: Run the following command to verify that Docker is functioning properly:
sudo docker run hello-world
Docker will pull the hello-world
image from the Docker Hub and run it in a container, displaying a message indicating the installation was successful.
Post-installation Steps for Linux (Optional)
After installation, you may want to configure Docker to allow running Docker commands without sudo
.
- Create a Docker Group:
sudo groupadd docker
-
Add Your User to the Docker Group:
Replace
username
with your actual username.
sudo usermod -aG docker $USER
- Log Out and Log Back In: For the group changes to take effect, log out and log back in, or run the following:
newgrp docker
-
Verify Without
sudo
: Run Docker commands without usingsudo
:
docker run hello-world
Conclusion
Docker is now successfully installed on your machine, whether it’s running Windows, macOS, or Linux. With Docker Desktop on Windows and macOS, you have an easy-to-use graphical interface to manage your containers. On Linux, Docker Engine is ready to use from the command line, and you’ve learned the necessary steps to run Docker without sudo
.
You can now begin creating Docker images, running containers, and exploring the world of containerization!
Top comments (0)