CentOS8 配置Docker环境

官网上有详细的步骤了。

在 CentOS 上安装 Docker 引擎 |Docker 文档 — Install Docker Engine on CentOS | Docker Docs

这里我尝试跟着走一遍,看看记录踩坑的地方。(实际上非常顺利,没有踩坑)

先执行这两条指令

1
sudo yum install -y yum-utils

结果:

1
2
3
4
5
6
7
8
Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/CentOS-Epel.repo; Configuration: OptionBinding with id "failovermethod" does not exist
Repository extras is listed more than once in the configuration
Repository epel is listed more than once in the configuration
Last metadata expiration check: 3:07:31 ago on Thu 14 Mar 2024 11:23:43 AM CST.
Package yum-utils-4.0.21-3.el8.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!

出现了一点警告,但好像也没事

1
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

结果:

1
2
3
4
Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/CentOS-Epel.repo; Configuration: OptionBinding with id "failovermethod" does not exist
Repository extras is listed more than once in the configuration
Repository epel is listed more than once in the configuration
Adding repo from: https://download.docker.com/linux/centos/docker-ce.repo

还是警告,但好像也没事

然后开始安装Docker引擎

1
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

中间出来一个total size:95M,问你是否继续安装,继续,y。

等了大概三五分钟,完成了。

启动docker

1
sudo systemctl start docker

验证

1
sudo docker run hello-world

出现了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/get-started/

说明安装成功了。

接下来该把自己的win11电脑上的镜像文件发到服务器上了。

首先要找到镜像文件,但没法直接通过搜索文件找到镜像文件。

需要用指令

格式如下:

1
docker save -o /path/to/save/image.tar yourimagename:tag

我输入的是

1
2
D:/Desktop> (先切换到桌面文件夹下)
D:/Desktop>docker save -o ./docker-test-py.tar docker-test-py:latest

这个tar文件有900多MB

然后把他上传到服务器上,还得等一会。我用的宝塔直接拖拽上传的。

接下来使用指令

1
docker load -i /path/to/your/image.tar

来加载刚刚上传的镜像文件

于是我输入了

1
docker load -i /home/bitmountain/docker-image/docker-test-py.tar

接着输入

1
docker images

发现确实有刚才的镜像文件了。

实际上刚才上传的900MB的tar后缀的镜像文件已经可以删掉了。不删也没事