Installing Docker and Docker Compose
Docker and Docker Compose are essential tools for creating, deploying, and managing containerized applications. This guide provides a step-by-step walkthrough on how to install Docker and Docker Compose on various operating systems.
Prerequisites
Before we start, ensure that you have:
- A supported operating system (Linux, Windows 10/11, macOS)
- Internet access to download Docker and Docker Compose
- Sudo or administrator privileges
Installing Docker
Installing on Linux
Update your package index:
sudo apt-get update
Install required packages:
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Set up the stable repository:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Install Docker Engine:
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
Verify installation:
sudo docker --version
Installing on Windows
Download Docker Desktop for Windows:
Visit Docker Hub and download the Docker Desktop Installer.
Run the Installer:
Follow the on-screen instructions to complete the installation.
Verify installation:
docker --version
Installing on macOS
Download Docker Desktop for Mac:
Visit Docker Hub and download the Docker Desktop Installer.
Run the Installer:
Open the .dmg
file and drag Docker to the Applications folder.
Start Docker:
Open Docker from the Applications folder.
Verify installation:
docker --version
Installing Docker Compose
Installing on Linux
Download the Docker Compose binary:
sudo curl -L "https://github.com/docker/compose/releases/download/$(sudo curl -s https://api.github.com/repos/docker/compose/releases/latest | grep 'tag_name' | cut -d\" -f4)/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Apply executable permissions:
sudo chmod +x /usr/local/bin/docker-compose
Verify installation:
docker-compose --version
Installing on Windows
Download Docker Compose:
Docker Compose is included with Docker Desktop. Make sure the Docker Desktop is running.
Verify installation:
Open Command Prompt or PowerShell and run:
docker-compose --version
Installing on macOS
Download Docker Compose:
Docker Compose is included with Docker Desktop. Make sure the Docker Desktop is running.
Verify installation:
Open Terminal and run:
docker-compose --version
Post-Installation Steps
Create Docker Group (Linux only):
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
Enable and Start Docker (Linux only):
sudo systemctl enable docker
sudo systemctl start docker
Troubleshooting
Docker Daemon Issues:
Verify the Docker service is running:
sudo systemctl status docker
Permission Denied Errors:
Ensure your user has the appropriate permissions and is part of the ‘docker’ group.
Network Issues:
Check firewall settings and ensure Docker is allowed through.
Feel free to reach out for more help through Docker’s community forums or their official documentation.