shitou@shitou:~$ sudo docker images -a   #查看镜像
REPOSITORY                         TAG       IMAGE ID       CREATED         SIZE
shitouubuntu                       1.0       f3bf725a6c29   4 days ago      78.1MB
localhost:5000/shitouubuntu        1.0       f3bf725a6c29   4 days ago      78.1MB
tomcat                             latest    3c65deadf104   9 days ago      511MB
jc21/nginx-proxy-manager           latest    1e836ffe2bd6   13 days ago     1.09GB
nginx                              latest    97662d24417b   13 days ago     192MB
ubuntu                             latest    a04dc4851cbc   3 weeks ago     78.1MB
registry.fit2cloud.com/halo/halo   2.20.14   e1fc683d04a6   3 weeks ago     428MB
mysql                              latest    a52cba19e8cc   3 weeks ago     797MB
blinkospace/blinko                 latest    442a006bde00   5 weeks ago     573MB
registry.fit2cloud.com/halo/halo   2.20      c6b280648229   6 weeks ago     427MB
adguard/adguardhome                latest    b715c7b6b7a1   2 months ago    71.3MB
nginx                              <none>    f876bfc1cc63   2 months ago    192MB
postgres                           latest    4bc6cc20ca7a   2 months ago    435MB
amuluze/amprobe                    latest    84f6a8b97020   3 months ago    291MB
amuluze/amprobe                    v1.3.9    84f6a8b97020   3 months ago    291MB
accetto/ubuntu-vnc-xfce            latest    2db0852dc195   11 months ago   796MB
registry                           2         282bd1664cf1   16 months ago   25.4MB
mysql                              8.1.0     ae2502152260   19 months ago   574MB
nginx                              1.23.4    a7be6198544f   21 months ago   142MB
wiznote/wizserver                  latest    c1ad683bc530   2 years ago     3.34GB
shitou@shitou:~$ docker save -o my_mysql_810_image.tar mysql/mysql-repo:8.1.0           Error response from daemon: reference does not exist
shitou@shitou:~$ sudo docker save -o my_mysql_810_image.tar mysql/mysql-repo:8.1.0
Error response from daemon: reference does not exist
shitou@shitou:~$ docker save -o mysql_8.1.0.tar ae2502152260

shitou@shitou:~$
shitou@shitou:~$ ls -lh mysql_8.1.0.tar
-rw------- 1 shitou shitou 562M Feb 19 15:08 mysql_8.1.0.tar
shitou@shitou:~$ ls
adminhome  data    halo       jx               Netdata      shitou  ubuntu.sources.list
amprobe    docker  hub        kickstart.sh     registry     ub      usr.sbin.libvirtd
bk         go      installer  mysql_8.1.0.tar  registry.sh  ubuntu
shitou@shitou:~$ scp mysql_8.1.0.tar shitou@39.106.35.236:/home/shitou
The authenticity of host '39.106.35.236 (39.106.35.236)' can't be established.
ED25519 key fingerprint is SHA256:LA+k516fWXlUW3nkqVd9eWStqODKq3FEUNNBbqTaP8s.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '39.106.35.236' (ED25519) to the list of known hosts.
shitou@39.106.35.236's password:
mysql_8.1.0.tar                                       100%  562MB  11.9MB/s   00:47
shitou@shitou:~$ cat /etc/docker/daemon.json
{"registry-mirrors":

       ["https://docker.211678.top",
        "https://docker.lpanel.live",
        "https://hub.rat.dev",
        "https://docker.m.daocloud.io",
        "https://do.nark.eu.org",
        "https://dockerpull.com",
        "https://dockerproxy.cn",
        "https://docker.aws19527.cn",
        "https://docker.erduoya.top"]
}

1. 导出镜像

在终端中执行以下命令来导出镜像:

收起

bash

docker save -o mysql_8.1.0.tar ae2502152260

  • docker save:这是 Docker 用于保存镜像为 .tar 文件的命令。

  • -o:该选项用于指定输出文件的名称,这里我们将输出文件命名为 mysql_8.1.0.tar,你可以根据需求修改文件名,但要注意遵循文件命名规则。

  • ae2502152260:这是你要导出的镜像的 ID。

执行该命令后,Docker 会开始将镜像的各个层打包到指定的 .tar 文件中,这个过程可能需要一些时间,具体取决于镜像的大小。

2. 验证导出结果

你可以使用 ls 命令查看当前目录下是否生成了 mysql_8.1.0.tar 文件,同时可以查看文件的大小,大致判断导出是否成功:

收起

bash

ls -lh mysql_8.1.0.tar

该命令会以人类可读的格式显示文件的详细信息,包括文件大小等。

3. 传输到云服务器

如果你要将导出的镜像传输到云服务器,可以使用 scp 命令(前提是云服务器开启了 SSH 服务),示例命令如下:

收起

bash

scp mysql_8.1.0.tar your_username@your_server_ip:/path/on/server

  • your_username:你登录云服务器使用的用户名。

  • your_server_ip:云服务器的 IP 地址。

  • /path/on/server:你希望将文件传输到云服务器的目标路径,例如 /home/your_username

4. 在云服务器上加载镜像

登录到云服务器后,使用 docker load 命令将传输过来的 .tar 文件加载为 Docker 镜像:

收起

bash

docker load -i /path/on/server/mysql_8.1.0.tar

  • -i:用于指定要加载的 .tar 文件的路径。

加载完成后,你就可以在云服务器上使用这个 MySQL 8.1.0 镜像来创建容器了