Installing and Configuring Docker on Linux

Installing and Configuring Docker on Linux
12 Jan

Prerequisites

Before installing Docker on a Linux system, ensure you have:

  1. A 64-bit installation of a compatible Linux distribution.
  2. Root or a user with sudo privileges.
  3. 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

  1. Update Your System:
    bash
    sudo apt update
    sudo apt upgrade -y

  2. Install Required Packages:
    bash
    sudo apt install apt-transport-https ca-certificates curl software-properties-common -y

  3. 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

  4. 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

  5. Install Docker Engine:
    bash
    sudo apt update
    sudo apt install docker-ce docker-ce-cli containerd.io -y

  6. Verify Installation:
    bash
    sudo systemctl status docker
    docker --version

Installing Docker on CentOS

  1. Update Your System:
    bash
    sudo yum update -y

  2. Install Required Packages:
    bash
    sudo yum install -y yum-utils

  3. Set Up Docker Repository:
    bash
    sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

  4. Install Docker Engine:
    bash
    sudo yum install docker-ce docker-ce-cli containerd.io -y

  5. Start Docker:
    bash
    sudo systemctl start docker
    sudo systemctl enable docker

  6. Verify Installation:
    bash
    sudo systemctl status docker
    docker --version

Installing Docker on Debian

  1. Update Your System:
    bash
    sudo apt update
    sudo apt upgrade -y

  2. Install Required Packages:
    bash
    sudo apt install apt-transport-https ca-certificates curl gnupg lsb-release -y

  3. 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

  4. 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

  5. Install Docker Engine:
    bash
    sudo apt update
    sudo apt install docker-ce docker-ce-cli containerd.io -y

  6. Verify Installation:
    bash
    sudo systemctl status docker
    docker --version

Post-Installation Steps

Managing Docker as a Non-Root User

  1. Create Docker Group:
    bash
    sudo groupadd docker

  2. Add Your User to the Docker Group:
    bash
    sudo usermod -aG docker $USER

  3. Apply the New Group Membership:
    bash
    newgrp docker

  4. 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

  1. Check Docker Logs:
    bash
    sudo journalctl -u docker

  2. 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

Leave a Reply

Your email address will not be published. Required fields are marked *

Looking for the best web design
solutions?