最佳方案就是查看官方文档了
https://docs.docker.com/engine/install/centos/#install-from-a-package
在docker官网找到centos安装目录,里面有个Install from a package 章节,其他系统也可以在相应系统类别里找到对应章节
Install from a package
If you can't use Docker's rpm repository to install Docker Engine, you can download the .rpm file for your release and install it manually. You need to download a new file each time you want to upgrade Docker Engine.
-
Go to https://download.docker.com/linux/centos/ and choose your version of CentOS. Then browse to
x86_64/stable/Packages/and download the.rpmfile for the Docker version you want to install. -
Install Docker Engine, changing the path below to the path where you downloaded the Docker package.
$ sudo yum install /path/to/package.rpmDocker is installed but not started. The
dockergroup is created, but no users are added to the group. -
Start Docker.
$ sudo systemctl start docker -
Verify that the Docker Engine installation is successful by running the
hello-worldimage.$ sudo docker run hello-worldThis command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message and exits.
You have now successfully installed and started Docker Engine.
Tip
Receiving errors when trying to run without root?
The
dockeruser group exists but contains no users, which is why you’re required to usesudoto run Docker commands. Continue to Linux postinstall to allow non-privileged users to run Docker commands and for other optional configuration steps.
安装完成后还有个建议章节:https://docs.docker.com/engine/install/linux-postinstall/
跟着里面操作,可以让非root用户操作docker,以及设置docker自动启动等
你以为到此就结束了?本来我也是这么想的,直到来到第二步,我蒙了。。
下面为我的操作记录:
1.查看系统版本,根据系统版本下载docker离线包
cat /etc/redhat-release

我是centos8,所以访问 https://download.docker.com/linux/centos/8/x86_64/stable/Packages/
把每个包依次下载最新版

下载之后上传服务器,文件如下

2.安装docker
本来就以为一切就结束的时候问题来了。。
sudo yum install /path/to/package.rpm
看到这个,我肯定是想按顺序一个一个安装啊
安装第一个没问题,安装第二个报错了

安装docker-ce 报错缺少依赖 docker-ce-cli docker-ce-rootless
安装docker-ce-rootless 报错缺少依赖 docker-ce
到这里我蒙圈了,这不是死循环吗
思考片刻后,我在想既然这样要不整体安装试试,死马当活马医了
于是抱着半信半疑的态度试了下

居然成功了,我可真是个天才~
所以,这里安装需要把所有组件都带上安装
yum install -y containerd.io-1.6.9-3.1.el8.x86_64.rpm docker-buildx-plugin-0.11.2-1.el8.x86_64.rpm docker-ce-24.0.6-1.el8.x86_64.rpm docker-ce-cli-24.0.6-1.el8.x86_64.rpm docker-ce-rootless-extras-24.0.6-1.el8.x86_64.rpm docker-compose-plugin-2.6.0-3.el8.x86_64.rpm docker-scan-plugin-0.9.0-3.el8.x86_64.rpm
3.按提示章节完成后续操作
https://docs.docker.com/engine/install/linux-postinstall/
4.docker-compose安装