20210129docker-aarch64v8

Jan 29, 2021

Docker服务运行在aarch64 服务器

之前公司的服务都在x86架构服务器上,机缘下客户提供了一台华为云的aarch64 服务器。

一开始我以为也就最多2小时全部搞完毕,没想到2小时环境都搭不起来,docker 都运行不了。两天才搞好。

安装yum 源

首先试了下原本的源很慢很慢,$ sudo yum update 超级慢。

故使用 $ sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup && sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

发现$ sudo yum makecache 一直报404错误。

$ arch # 或者uname -a 看到aarch64.

网上查是arm64 位版本。

根据文章,使用以下ali云源内容替换 /etc/yum.repos.d/CentOS-Base.repo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.aliyun.com/centos-altarch/$releasever/os/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.aliyun.com/centos-altarch/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.aliyun.com/centos-altarch/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
enabled=1

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.aliyun.com/centos-altarch/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

其他没有替换,接下来执行:

sudo yum clean all && sudo yum makecache sudo yum update 速度很快。

安装Docker Docker-compose

1
2
3
4
5
6
7
8
9
10
11
12
13
$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2

$ sudo yum-config-manager --add-repo https://download.docker.com/Linux/centos/docker-cce.repo

$ sudo yum update

$ sudo yum install docker-ce

$ sudo usermod -aG docker ${USER_NAME} # 加入docker到用户组

$ sudo systemctl enable docker # 添加docker到开机启动

$ sudo docker run hello-world # 验证安装

安装docker-compose:

$ sudo yum install -y docker-compose

服务适配aarch64

此时启动服务会报: exec user process caused "exec format error"

说明该服务镜像不支持aarch64架构。

根据文章2, 成功打了对应的包:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# docker 版本大于2.0以上
#勾选 Preference - Command Line - Enable experimental features

$ docker buildx ls
NAME/NODE DRIVER/ENDPOINT STATUS PLATFORMS
default docker
default default running linux/amd64, linux/arm64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6

# 我们当前使用的是一个默认builder,我们创建一个新的builder 替换老的builder
$ docker buildx create --name mybuilder
mybuilder
# 使用该builder
$ docker buildx use mybuilder
# --bootstrap 不是必须的,他形容了立即开启编译容器
$ docker buildx inspect --bootstrap

此时根据之前的服务,再打一个arm64 的包:

1
2
3
4
5
6
7
8
# 构建平台为arm64架构镜像并推送到package
$ docker buildx build --platform linux/arm64 -t akerdi/onlyone:arm64-20210112 --push registry.akerdi.com/akerdi/onlyone .
# 查看镜像信息
$ docker buildx imagetools inspect akerdi/onlyone:arm64-20210112
# 下载该镜像并运行
$ docker run -p 7200:7200 --rm registry.akerdi.com/akerdi/onlyone:arm64-20210112
# 将该镜像保存
$ docker save -o onlyone.tar registry.akerdi.com/akerdi/onlyone:arm64-20210112

我们也可以运行并查看是否是对应平台包:

docker run --rm registry.akerdi.com/akerdi/onlyone:arm64-20210112 uname -m