Docker安装指定版本:如何获取版本字符串及构造规则?
Hey there! I’ve been in your exact situation before—needing to roll back Docker to avoid a buggy latest release, but struggling to track down the exact version string to use. Let’s break this down step by step, no external docs required.
First: List All Available Docker CE Versions
The easiest way to get a full list of installable versions for your system is using your package manager directly. It’ll show you the exact version strings you need to specify:
For Debian/Ubuntu-based systems
Run this command to pull up all available Docker CE versions:
apt-cache madison docker-ce
You’ll see output like this (truncated example):
docker-ce | 5:24.0.6-1ubuntu.22.04jammy | https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
docker-ce | 17.12.1ce-0ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
For RHEL/CentOS/Fedora-based systems
Use this command to list and sort available versions in reverse order:
yum list docker-ce --showduplicates | sort -r
Sample output:
docker-ce.x86_64 3:24.0.6-1.el8 docker-ce-stable
docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable
Second: Install the Exact Version You Need
Once you’ve copied the full version string from the list above, use it to install that specific release:
Debian/Ubuntu
sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
Example for 17.12.1 on Ubuntu Xenial:
sudo apt-get install docker-ce=17.12.1~ce-0~ubuntu-xenial docker-ce-cli=17.12.1~ce-0~ubuntu-xenial containerd.io
RHEL/CentOS
sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
Example for 17.12.1 on CentOS 7:
sudo yum install docker-ce-17.12.1.ce-1.el7.centos docker-ce-cli-17.12.1.ce-1.el7.centos containerd.io
Bonus: Understand the Version String Pattern
Docker CE version strings follow a consistent, distro-specific pattern:
- For Debian/Ubuntu:
<major>.<minor>.<patch>~ce-0~<distro>-<codename>(e.g.,17.12.1~ce-0~ubuntu-xenial) - For RHEL/CentOS:
<major>.<minor>.<patch>.ce-<release>.<distro codename>(e.g.,17.12.1.ce-1.el7.centos)
This ensures the package manager installs the correct build for your operating system.
Prevent Accidental Updates
After installing your desired version, lock it to avoid automatic updates to a newer (potentially problematic) release:
- Debian/Ubuntu:
sudo apt-mark hold docker-ce docker-ce-cli - RHEL/CentOS:
sudo yum versionlock docker-ce docker-ce-cli
You can verify the installed version anytime with:
docker --version
内容的提问来源于stack exchange,提问作者cool

