ARM架构银河麒麟使用笔记-下载docker软件包及所有依赖包并在离线环境下安装

ARM架构银河麒麟使用笔记-下载docker软件包及所有依赖包并在离线环境下安装

目的是在arm架构的银河麒麟操作系统V10中安装docker。

一、给虚拟机创建快照

1. 创建

qemu-img snapshot -c EmptyKylin rootfs.qcow2 

2. 查看

qemu-img snapshot -l rootfs.qcow2 

3. 恢复

qemu-img snapshot -a EmptyKylin rootfs.qcow2 

二、启动银河麒麟虚拟机

到虚拟机的存放目录下,使用以下命令来启动虚拟机。

sudo qemu-system-aarch64 -m 4096 -cpu cortex-a72 -smp 4,cores=4,threads=1,sockets=1 -M virt -bios QEMU_EFI.fd -net nic,model=pcnet -device nec-usb-xhci -device usb-kbd -device usb-mouse -device VGA -device virtio-scsi-device -drive if=none,file=rootfs.qcow2,id=hd0 -device virtio-blk-device,drive=hd0 -net tap -net nic

这个命令使用的前提是:QEMU_EFI.fdrootfs.qcow2,并且事先配置了NAT网络。

三、创建目录

这个目录用于存放要下载的软件及软件包

sudo mkdir -p /Docker-Kylin-OfflinePackages/archives

sudo chmod -R 777 /Docker-Kylin-OfflinePackages

四、下载docker并保存

直接使用apt install来安装docker是不行的,找不到软件源。所以要先配置docker的软件源。

1. 设置docker源

参考的是Docker CE 镜像源站执行如下命令,第三步我是做了修改的。

1-1. step 1: 安装必要的一些系统工具

sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common

1-2. step 2: 安装GPG证书

curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

1-3. Step 3: 写入软件源信息

编辑文件/etc/apt/sources.list.d/docker.list,向其中加入如下一行

deb [arch=arm64 https://mirrors.aliyun.com/docker-ce/linux/debian bullseye stable

1-4. Step 4: 更新

sudo apt update

2. 下载软件包及依赖包

2-1. 执行下载命令

下面的命令会将docker-cedocker-ce-rootless-extrasdocker-buildx-plugindocker-compose-plugin以及它们的递归依赖都下载到/Docker-Kylin-OfflinePackages/archives目录内:


cd /Docker-Kylin-OfflinePackages/archives
sudo apt-get download $(apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances docker-ce docker-ce-rootless-extras docker-buildx-plugin docker-compose-plugin | grep "^\w" | sort -u)

结果如下,可以看到,一共下载了120个软件包。
enter description here

五、建立软件源

cd /Docker-Kylin-OfflinePackages
apt-ftparchive packages archives > archives/Packages
cd archives/
gzip -c Packages > Packages.gz
touch release
apt-ftparchive release ./ > Release

完成以上命令后,把Docker-Kylin-OfflinePackages这个目录找个地方保存起来,以后复制到离线机器上之后,执行接下来的步骤,应该就可以用了。

六、修改配置文件

把原有的指向互联网的源都注释掉,增加一个以刚才创建的目录为来源的软件源,就可以代表着离线状态了。同时我把互联网的连接也断掉了。

1. 修改/etc/apt/sources.list

注释掉原来的源,增加自建的源。修改后的结果为:

# 本文件由源管理器管理,会定期检测与修复,请勿修改本文件
# deb http://archive.kylinos.cn/kylin/KYLIN-ALL 10.1-2303-updates main universe multiverse restricted
# deb http://archive.kylinos.cn/kylin/KYLIN-ALL 10.1 main restricted universe multiverse
# deb http://archive2.kylinos.cn/deb/kylin/production/PART-V10-SP1/custom/partner/V10-SP1 default all
deb [trusted=yes] file:/Docker-Kylin-OfflinePackages archives/

2. 修改/etc/apt/sources.list.d/docker.list

注释掉其中的内容。

3. 修改/etc/dpkg/dpkg.cfg文件,禁止银河麒麟的签名验证

把文件中allow-kylinsignverify-kylinsign两行注释掉。否则后面安装软件的时候会提示验证失败无法安装。

4. 更新缓存

sudo apt clean
sudo apt update

得到如下结果
enter description here

七、安装docker

执行命令:

sudo apt install docker-ce docker-ce-rootless-extras docker-buildx-plugin docker-compose-plugin

过程及结果如下:
enter description here
enter description here
enter description here

八、测试使用docker

在下面的测试过程中,如果出现权限问题,请使用sudo

1. 查看当前docker服务状态

systemctl status docker

2. 启动docker服务

systemctl start docker

3. 查看所有的镜像

docker image ls

4. 导入hello-world镜像

事先在当前目录下有一个hello-world.tar的压缩包,是从别的地方导出的一个测试容器。
使用docker load -i hello-world.tar命令导入这个容器。
enter description here

5. 运行导入的镜像

使用docker run hello-world来运行导入的镜像
enter description here
问题是,导入的那个镜像是(linux/amd64)平台的,也就是x86_64架构,而运行docker的这个银河麒麟操作系统使用的是(linux/arm64/v8)平台,是arm64架构,两种架构不一样,没有办法运行。

6. 查看所有的容器

使用命令docker ps -a查看所有的容器
enter description here

九、离线源应用

1. 关闭刚才的虚拟机

2. 恢复快照

qemu-img snapshot -a EmptyKylin rootfs.qcow2 

3. 启动银河麒麟虚拟机

sudo qemu-system-aarch64 -m 4096 -cpu cortex-a72 -smp 4,cores=4,threads=1,sockets=1 -M virt -bios QEMU_EFI.fd -net nic,model=pcnet -device nec-usb-xhci -device usb-kbd -device usb-mouse -device VGA -device virtio-scsi-device -drive if=none,file=rootfs.qcow2,id=hd0 -device virtio-blk-device,drive=hd0 -net tap -net nic

4. 复制软件包到新的离线机器上

sudo scp -r Docker-Kylin-OfflinePackages wd@192.168.53.77:/home/wd

5. 修改配置文件

下面的操作顺序是有讲究的。如果第三步不在第四步的前面,会出现类似于elease 的 Release 文件已经过期(已经过期了 7小时 23分 21秒)。该仓库的更新将不会应用这种错误。

5-1. 修改/etc/dpkg/dpkg.cfg文件,禁止银河麒麟的签名验证

把文件中allow-kylinsignverify-kylinsign两行注释掉。否则后面安装软件的时候会提示验证失败无法安装。

5-2. 把所有的软件源都注释掉

在我这里的虚拟机环境中,只需要修改/etc/apt/sources.list,注释掉里面的所有源。

5-3. 清除缓存

sudo apt clean

5-4. 增加软件源

编辑/etc/apt/sources.list,在后面增加如下一行:

deb [trusted=yes] file:/home/wd/Docker-Kylin-OfflinePackages archives/

这里的文件路径要根据自己上传的位置来写。

5-5. 更新软件源

sudo apt update

得到如下结果
enter description here

6. 安装docker

执行命令:

sudo apt install docker-ce docker-ce-rootless-extras docker-buildx-plugin docker-compose-plugin

结果如下:
enter description here
查看docker服务、导入hello-world、启动hello-world和前面都一样。
到这里就结束了。

posted @ 2024-04-02 10:38  南宫二狗  阅读(288)  评论(0编辑  收藏  举报