Hello! Are you wasting too much time setting up your development environment? 🤯 Are you tired of saying, “It works on my machine, why not on yours?” 🚢 Docker is a magical tool that can solve all of your problems in one fell swoop! 🚢.
In this article, I’ll walk you through a detailed installation of Docker for your operating system (Windows, macOS, Linux). Don’t stress about configuration anymore! Let’s dive into the world of Docker together 🚀.
—.
📚 What is Docker and why should I use it?
Docker is a platform that bundles an application and all the components needed to run it (code, runtime, system tools, libraries, etc.) into a single package (container). It’s like a virtual machine (VM), but much lighter and faster.
Why you should use Docker:.
-
- Consistent environment:** Delivers on the “if it works on my machine, it works everywhere” promise. Your development, testing, and deployment environments are all the same 👍.
- Isolation:** Each container runs independently, so problems in one container don’t affect other containers or the host system.
- Portability: Once created, containers work the same in any environment where Docker is installed. Cloud, on-premises, anywhere!
- Efficient: Instead of virtualizing the entire OS like a virtual machine, containers use system resources efficiently by sharing only the parts you need.
—.
🛠️ What to do before installing Docker
Before you start installing Docker, you’ll need a few basic things.
- Operating System:
- Windows 10 64-bit (Home, Pro, Enterprise, or Education) or later version
- macOS (Intel chip or Apple Silicon chip)
- Linux (Ubuntu, Debian, CentOS, Fedora, etc.)
- administrator privileges:** System administrator privileges are required for installation and setup.
- stable internet connection:** Docker installation files and required packages need to be downloaded.
- sufficient system resources:** Minimum 4 GB RAM recommended (8 GB or more for Docker Desktop).
Once you’re ready, let’s get started with the installation!
—.
💻 How to install Docker on your operating system
Each operating system has a slightly different way to install Docker. Find the section for your OS and follow along.
1. Installing Docker on Windows (Docker Desktop)
On Windows, installing Docker Desktop is the most common and recommended way to install Docker. Docker Desktop runs on top of Windows Subsystem for Linux 2 (WSL 2), so you’ll need to enable WSL 2 first.
For a step-by-step installation guide:
-
Enable WSL 2 and install your Linux distribution:
- Open PowerShell or a command prompt with administrator privileges.
- Run the following command to activate WSL and install the required features.
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
- Reboot your system (required!) 🔄
- After rebooting, run the following command to set WSL 2 as the default version and install a Linux distribution (e.g. Ubuntu).
wsl --install # This command will activate WSL, install Ubuntu, and default WSL2 all at once.
If
wsl --install
does not work, manually search for and install Ubuntu from the Microsoft Store and run the following command.wsl --set-default-version 2
- Once Ubuntu is installed, proceed with the initial setup (username, password).
-
Download Docker Desktop: Download Docker Desktop.
- Access the Docker official website and download Docker Desktop for Windows. Docker Desktop download link
- Click the “Download for Windows” button to get the installation file.
-
Install Docker Desktop:
- Run the downloaded
Docker Desktop Installer.exe
file. - Follow the prompts in the installation wizard. Make sure the “Enable WSL 2 Windows Features” option is checked.
- When the installation is complete, you may be prompted to restart your computer. It is recommended that you reboot.
- Run the downloaded
-
Run and set up Docker Desktop: Run Docker Desktop.
- After rebooting, click the Docker Desktop icon (on the desktop or start menu) to run it.
- On first launch, you may be asked to agree to the terms and log in (login is not required).
- Verify that Docker Desktop is running by looking at the tray icon (whale icon 🐳)
- In
Settings
->Resources
->WSL Integration
, make sure that the WSL 2 distribution you want to use Docker with is enabled. (It is usually enabled by default.)
-
Verify the installation:
- Open a PowerShell, command prompt, or Ubuntu terminal in WSL 2 and type the following command.
docker --version docker run hello-world
docker --version
outputs the Docker client and server version information.docker run hello-world
runs an example container to verify that Docker is working properly. If you see the message “Hello from Docker!”, you’ve succeeded! 🎉
- Open a PowerShell, command prompt, or Ubuntu terminal in WSL 2 and type the following command.
2. Installing Docker on Mac (macOS) (Docker Desktop)
On macOS, similar to Windows, it is easiest and recommended to install Docker Desktop.
Here is a step-by-step installation guide:.
-
Download Docker Desktop:
- Access the Docker official website and download Docker Desktop for Mac. Docker Desktop download link
- Select the version that matches your Mac chipset.
- Apple Silicon: Macs with M1, M2, M3 chips, etc.
Intel Chip: Macs with Intel processors (include
amd64
in the DMG file name)
- Apple Silicon: Macs with M1, M2, M3 chips, etc.
Intel Chip: Macs with Intel processors (include
-
Install Docker Desktop: Docker Desktop
- Open the downloaded
.dmg
file. - Drag and drop the
Docker.app
icon into theApplications
folder. - Run
Docker.app
from the Applications folder. - It may ask for permissions on first run. Click “Open” and enter your user password if required.
- Accept the terms and conditions and the initial setup wizard may appear.
- Open the downloaded
-
Run and set up Docker Desktop: * Run Docker Desktop.
- If the docker whale icon (🐳) appears in the menu bar, it is successfully launched.
- Click the icon to open the menu and use
Settings
to adjust resource allocation, etc.
-
To verify installation:
- Open Terminal (Terminal.app) and enter the following command.
docker --version docker run hello-world
docker --version
prints the Docker client and server version information.docker run hello-world
runs an example container to verify that Docker is working properly. If you see the message “Hello from Docker!”, you’ve succeeded! 🎉
- Open Terminal (Terminal.app) and enter the following command.
3. Installing Docker on Linux (on Ubuntu/Debian)
On Linux, you can install and use the Docker engine directly without Docker Desktop. The instructions here are based on the most popular Ubuntu/Debian-based systems. Other Linux distributions (CentOS, Fedora, etc.) can be installed in a similar way.
⚠️ Important: sudo
permissions are required.
Step-by-step installation guide:
-
Uninstall any existing Docker-related packages (optional):** If you have previously installed Docker, it is recommended that you uninstall it first to avoid conflicts.
sudo apt-get remove docker docker-engine docker.io containerd runc
-
Install the required packages: Install the required packages Install the
apt
utility and the necessary certificates to make the repository available over HTTPS.sudo apt-get update sudo apt-get install \ ca-certificates \ curl \ gnupg \ lsb-release
-
Add Docker’s official GPG key: /dev/null
-
Install the Docker Engine: apt package list and install the docker engine.
sudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
-
Start and Enable Docker Services: **Activate Docker Services Enable the Docker service to start automatically, and verify that it is currently running.
sudo systemctl start docker sudo systemctl enable docker sudo systemctl status docker
(If it says
Active: active (running)
, it is successful). -
Add a user to the docker group (mandatory! 💡): Add a user to the docker group. By default, the
docker
command requiressudo
privileges to run. If you don't want to usesudo
every time, you need to add the current user to thedocker
group.sudo usermod -aG docker $USER
After running this command, you must either logout and log back in or reboot your system for the changes to take effect.
-
Confirm the installation:
docker --version docker run hello-world ```bash docker --version The `docker --version` prints out the Docker client and server version information. docker run hello-world` runs an example container to verify that Docker is working properly. If you see the message "Hello from Docker!", you've succeeded! 🎉
—]
✅ Verify installation and initial setup
Common to all operating systems is how to verify that the Docker installation went well.
-
Check your Docker version: ** Run
docker --version
Example output:
Docker version 24.0.5, build 24.0.5-0ubuntu1~22.04.1
-
Run the
hello-world` container:** ** Run the
bash` container.docker run hello-world
This command downloads an image named
hello-world
from the Docker hub and runs a container with it. If you see a message like the one below, Docker is working perfectly.Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world ... Hello from Docker! This message shows that your installation appears to be working correctly. ...
Congratulations, you're now ready to run Docker containers on your machine! 🥳
—]
🚀 Learn basic Docker commands
Once you've completed your Docker installation, it's a good idea to familiarize yourself with some basic Docker commands.
`docker pull [image name]
: Download an image from Docker Hub.docker pull ubuntu:latest
docker images
: Shows a list of locally downloaded images.docker images
docker run [image name]
: Create and run a new container with a specific image.docker run -it ubuntu:latest bash # Run Ubuntu container and access bash shell
docker ps
: Show a list of currently running containers. docker ps -a`: Shows all containers (running or terminated).docker ps
docker stop [container ID or name]
: Stops a running container.docker stop my-nginx-container
docker rm [Container ID or name]
: Delete a stopped container.docker rm my-nginx-container
docker rmi [image ID or name]
: Delete a local image.docker rmi ubuntu:latest
—]
❓ Frequently Asked Questions & Troubleshooting
Common issues you may encounter during the installation process and how to resolve them.
docker: command not found
orPermission denied
(Linux):- Cause: The user was not added to the
docker
group, or did not re-login/reboot after being added. - Fix: Run the command
sudo usermod -aG docker $USER
, close the terminal completely and reopen it, or reboot the system.
- Cause: The user was not added to the
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
:- Cause: The docker service (daemon) is not running, or Docker Desktop is not running.
- Solution (Windows/macOS): Launch the Docker Desktop app and verify that the tray icon is enabled.
- Workaround (Linux): Run the
sudo systemctl start docker
command to start the Docker service.
- WSL2 related error on Windows:
- Cause: WSL2 update is required, or virtualization features (Intel VT-x / AMD-V) are disabled in the BIOS.
- Resolution:
- Update WSL to the latest version by running the
wsl --update
command. - Enable the virtualization feature in the computer BIOS settings (varies by manufacturer).
- Try temporarily disabling other virtualization software (VirtualBox, etc.) that might conflict with Hyper-V.
- Update WSL to the latest version by running the
-
hello-world
does not work even after installation:**- Cause: Network issues, firewall settings, insufficient resources on Docker Desktop, etc.
- Solution: Check your internet connection, and if you are using a corporate network or VPN, try disabling it for a while. Try increasing the memory/CPU allocated in the Docker Desktop settings.
—.
Closing remarks 🎉
You should now be able to successfully install Docker and handle basic commands! Docker is a powerful tool that can revolutionize your development and deployment workflows.
We hope this article has cleared up some of the confusion about installing Docker. Now you can get out of configuration purgatory and focus on writing code.
As a next step, try creating your own images using Dockerfiles, and learn how to manage multiple containers at once using Docker Compose. The world of Docker is endless!
If you have any questions, feel free to leave them in the comments. Have a great container journey! 🐳✨