Installing Docker Engine on Linux Systems
Quick Installation via Official Script
The fastest method to deploy Docker involves using the official convenience script. This approach handles repository setup and package installation automatically:
curl -fsSL https://get.docker.com | shTo accelerate the download process in certain regions, specify a mirror:
curl -fsSL https://get.docker.com | sh -s -- --mirror AliyunManual Installation on Ubuntu
For systems using the APT package manager, follow these steps to set up the Docker repository and install the engine.
First, prepare the system by updating the package index and installing prerequisite utilities:
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupgCreate a dedicated directory for the GPG key and import the Docker signing key:
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.ascConfigure the APT repository:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/nullRefresh the package index and install Docker Engine along with the containerd runtime and plugins:
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginTo lock the installation to a specific release, list available versions:
apt-cache madison docker-ceThen install using the version string:
sudo apt-get install -y docker-ce= docker-ce-cli= containerd.io Manual Installation on CentOS
On RPM-based distributions, install the yum-utils package first to manage repositories:
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repoProceed with the Docker Engine installation:
sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginStart and enable the Docker service:
sudo systemctl start docker
sudo systemctl enable dockerFor specific version installations, query available packages:
yum list docker-ce --showduplicates | sort -rInstall the desired version:
sudo yum install -y docker-ce- docker-ce-cli- containerd.io Verifying the Installation
Confirm that Docker Engine is installed correctly by checking the version:
docker --versionRun a test container to verify the daemon is functioning:
sudo docker run hello-worldNetwork Configuration
If containers require outbound network access, ensure IP forwarding is enabled:
# Edit /etc/sysctl.conf
net.ipv4.ip_forward = 1
# Apply changes
sudo sysctl -pFor container-to-container communication issues, adjust the iptables default policy:
sudo iptables -P FORWARD ACCEPTBuildKit Compatibility
Newer Docker versions enable BuildKit by default, which may cause issues with HTTP-based registries. To disable this feature, set the following environment variable:
echo "export DOCKER_BUILDKIT=0" >> ~/.bashrc
source ~/.bashrcWhen building images with caching issues, append the --no-cache flag to force a clean build:
docker build --no-cache -t myimage:latest .