Setting Up Docker on Ubuntu 18.04: Complete Installation Guide

Docker Overview

Docker is an open-source containerization platform that enables developers to package applications along with their dependencies into lightweight, portable containers, which can then be deployed across Linux environments.

Installation Procedure

Step 1: Remove Legacy Docker Versions

Ubuntu may ship with older Docker packages that need removal before installing the latest release:

sudo apt-get remove docker docker-engine docker.io containerd runc

Step 2: Refresh Package Index

sudo apt-get update

Step 3: Install Prerequisites

sudo apt-get install ca-certificates curl gnupg lsb-release apt-transport-https software-properties-common

Step 4: Add Official GPG Key

curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

Step 5: Configure Repository

sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

Step 6: Install Docker Engine

sudo apt-get install docker-ce docker-ce-cli containerd.io

Step 7: Grant Docker Access

Add your user account to the Docker group to avoid requiring sudo for every command:

sudo usermod -aG docker $USER

Verifying the Installation

Check the installed Docker version:

docker version

Run the test image to confirm everything works:

sudo docker run hello-world

On a fresh installation, the test image will be pulled automatically from Docker Hub since no local copies exist yet.

Configuring Registry Mirrors

If image pulls fail due to network latency or connectivity issues, configure mirror registries in the daemon settings. Edit or create the daemon configuration file:

sudo vim /etc/docker/daemon.json

Add the following mirror sources:

{
    "registry-mirrors": [
        "https://docker.m.daocloud.io",
        "https://dockerproxy.com",
        "https://docker.mirrors.ustc.edu.cn",
        "https://docker.nju.edu.cn"
    ]
}

Reload and restart the Docker service:

sudo systemctl daemon-reload
sudo systemctl restart docker

Run the verification command again:

sudo docker run hello-world

Tags: docker Ubuntu containerization installation Linux

Posted on Fri, 05 Jun 2026 17:23:54 +0000 by y.t.