docker构建多CPU镜像 - Fri, Dec 20, 2019
docker构建多CPU镜像
1. 概述
docker镜像是分平台的,不同平台的镜像不同.
如果docker的linux/arm64镜像运行在linux/amd64上,会报错exec format error
.
2. docker构建多CPU镜像基础
docker registry版本:v2.3+ docker 版本:1.10+
3. 开启image manifest编译功能
docker manifest的开启需要额外的配置,并且不能用于开发环境.
It should not be used in production environments.
配置docker的config.json文件
sudo vim .docker/config.json
添加"experimental": "enabled"
{
"auths": {
"https://index.docker.io/v1/": {
"auth": "a2Fpc2F3aW5kOjE5ODkwODEwTU1A"
}
},
"HttpHeaders": {
"User-Agent": "Docker-Client/19.03.3 (linux)"
},
"experimental": "enabled"
}
4. 创建多层镜像
docker manifest create csedge/device-serial-go:1.1.0-dev csedge/device-serial-go:1.1.0-arm64-dev csedge/device-serial-go:1.1.0-amd64-dev
docker manifest annotate csedge/device-serial-go:1.1.0-dev csedge/device-serial-go:1.1.0-arm64-dev --os linux --arch arm64
docker manifest annotate csedge/device-serial-go:1.1.0-dev csedge/device-serial-go:1.1.0-amd64-dev --os linux --arch amd64
docker manifest push csedge/device-serial-go:1.1.0-dev
查看manifest文件
docker manifest inspect csedge/device-serial-go:1.1.0-dev
{
"schemaVersion": 2,
"mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
"manifests": [
{
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"size": 735,
"digest": "sha256:cdcdfce4612155dbec008ac701652ae4136892da1989d4eeb24a4fa12912b8eb",
"platform": {
"architecture": "amd64",
"os": "linux"
}
},
{
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"size": 735,
"digest": "sha256:68644d08038f7add8cffc5c39688f47a23ff3cde0a92fb2ab163881be1bfe02d",
"platform": {
"architecture": "arm64",
"os": "linux"
}
}
]
}