最佳方案就是查看官方文档了
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.rpm
file 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.rpm
Docker is installed but not started. The
docker
group 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-world
image.$ sudo docker run hello-world
This 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
docker
user group exists but contains no users, which is why you’re required to usesudo
to 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/
docker官网连不上了,这里推荐用清华源 https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/
把每个包依次下载最新版,注意这里不是最下面的都是最新版,要看时间才准确
下载之后上传服务器,文件如下
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
或者直接在安装目录里执行
yum install -y *
3.按提示章节完成后续操作
https://docs.docker.com/engine/install/linux-postinstall/
经过检查docker没有开启自启动,把他设置为开启
$ sudo systemctl enable docker.service
$ sudo systemctl enable containerd.service
4.docker-compose安装
docker compose对于docker一键部署应用太重要了,果断要安装上
官方文档:https://docs.docker.com/compose/install/standalone/
查看官网文档得知
On Linux
Compose standalone
Note that Compose standalone uses the
-compose
syntax instead of the current standard syntaxcompose
.
For example typedocker-compose up
when using Compose standalone, instead ofdocker compose up
.
好家伙这里的意思为
docker compose的标准语法为:docker compose up -d
这是在安装了docker compose插件之后的标准语法
独立安装docker compose之后的语法为:docker-compose up -d
查看了之前的安装包,是有docker compose插件的,执行命令确认可用之后,就不用单独安装了