Installing and Configuring Docker on Linux
Prerequisites
Before installing Docker on a Linux system, ensure you have:
- A 64-bit installation of a compatible Linux distribution.
- Root or a user with
sudo
privileges. - Internet access for downloading packages.
Supported Linux Distributions
Docker supports several Linux distributions. This guide will cover the installation process for:
- Ubuntu
- CentOS
- Debian
Table 1: Supported Distributions
Distribution | Version Requirements |
---|---|
Ubuntu | 18.04 LTS or later |
CentOS | 7 or later |
Debian | 10 or later |
Step-by-Step Installation
Installing Docker on Ubuntu
-
Update Your System:
bash
sudo apt update
sudo apt upgrade -y -
Install Required Packages:
bash
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y -
Add Docker’s Official GPG Key:
bash
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg -
Set Up Docker Repository:
bash
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:
bash
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io -y -
Verify Installation:
bash
sudo systemctl status docker
docker --version
Installing Docker on CentOS
-
Update Your System:
bash
sudo yum update -y -
Install Required Packages:
bash
sudo yum install -y yum-utils -
Set Up Docker Repository:
bash
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo -
Install Docker Engine:
bash
sudo yum install docker-ce docker-ce-cli containerd.io -y -
Start Docker:
bash
sudo systemctl start docker
sudo systemctl enable docker -
Verify Installation:
bash
sudo systemctl status docker
docker --version
Installing Docker on Debian
-
Update Your System:
bash
sudo apt update
sudo apt upgrade -y -
Install Required Packages:
bash
sudo apt install apt-transport-https ca-certificates curl gnupg lsb-release -y -
Add Docker’s Official GPG Key:
bash
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg -
Set Up Docker Repository:
bash
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null -
Install Docker Engine:
bash
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io -y -
Verify Installation:
bash
sudo systemctl status docker
docker --version
Post-Installation Steps
Managing Docker as a Non-Root User
-
Create Docker Group:
bash
sudo groupadd docker -
Add Your User to the Docker Group:
bash
sudo usermod -aG docker $USER -
Apply the New Group Membership:
bash
newgrp docker -
Verify Docker Runs Without
sudo
:
bash
docker run hello-world
Configuring Docker to Start on Boot
Enable Docker to start at boot time:
sudo systemctl enable docker
Checking Docker Service Status
To check the status of the Docker service:
sudo systemctl status docker
Docker Configuration Files
Docker Daemon Configuration File
Docker’s configuration parameters are stored in /etc/docker/daemon.json
. Example configuration:
{
"log-driver": "json-file",
"log-level": "warn",
"storage-driver": "overlay2"
}
Reload Daemon and Restart Docker
After making changes to daemon.json
, reload and restart Docker:
sudo systemctl daemon-reload
sudo systemctl restart docker
Troubleshooting Common Issues
Docker Service Fails to Start
-
Check Docker Logs:
bash
sudo journalctl -u docker -
Verify Configuration:
Ensure no syntax errors in/etc/docker/daemon.json
.
Problems with Docker Commands
Ensure the user is added to the docker group:
groups $USER
If not, follow the steps under “Managing Docker as a Non-Root User.”
Summary Table: Common Commands
Command | Description |
---|---|
sudo systemctl start docker |
Start Docker service |
sudo systemctl stop docker |
Stop Docker service |
sudo systemctl restart docker |
Restart Docker service |
sudo systemctl enable docker |
Enable Docker to start at boot |
docker version |
Display Docker version information |
docker info |
Display system-wide information |
docker run hello-world |
Run a test Docker container |
By following these detailed instructions, you can confidently install and configure Docker on a Linux system, enabling you to efficiently manage containerized applications.
0 thoughts on “Installing and Configuring Docker on Linux”