System Preparation and Cleanup
Before initiating the installation of Docker Engine, it is crucial to remove any conflicting legacy packages that may exist on the system. This ensures a clean environment for the containerization tools.
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get updateInstalling Dependencies
Install the necessary prerequisite packages that allow apt to utilize repositories over HTTPS.
sudo apt-get install -y ca-certificates curl gnupg lsb-releaseConfiguring the Docker Repository
To facilitate faster downloads and ensure connectivity, use the Aliyun mirror for the Docker repository. First, add the official GPG key.
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpgNext, set up the repository using the added key.
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get updateInstalling Docker Engine
Install the latest version of Docker Engine, the command-line interface, and the containerd runtime.
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginManaging Docker as a Non-Root User
The Docker daemon binds to a Unix socket instead of a TCP port. By default, this socket is owned by the user root. To avoid using sudo for every command, add the current user to the docker group.
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp dockerConfiguring Image Acceleration
To optimize image pull speeds, configure the Docker daemon to use a registry mirror. Create or modify the daemon. configuration file.
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon. <<-'EOF'
{
"registry-mirrors": [
"https://docker.m.daocloud.io"
]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker