正文
buildx 多架构编译
安装docker
下载docker
下载buildx
安装架构支持
docker run --privileged --rm tonistiigi/binfmt --install all
创建一个自己的空间
buildx create --use --name mybuilder
检查支持的架构
buildx inspect mybuilder --bootstrap
Nodes:
Name: mybuilder0
Endpoint: unix:///var/run/docker.sock
Status: running
Buildkit: v0.11.6
Platforms: linux/arm64, linux/amd64, linux/amd64/v2, linux/riscv64, linux/ppc64le, linux/s390x, linux/mips64le, linux/mips64
打包镜像
dockerfile 的信息为:
# 注意from 好像不能写带架构的. 会根据platform自动进行下载. 比较简单.
FROM docker.io/adoptopenjdk/openjdk8
WORKDIR /app
COPY /app /app
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Dloader.path=./server/runtime/3rd,./server/runtime/libs","-Dparallel.startup=true","-Dserver.runtime.path.name=server","-XX:+UseContainerSupport","-XX:MaxRAMPercentage=75.0","-XX:InitialRAMPercentage=75.0","-XX:MinRAMPercentage=75.0","-XX:-DisableExplicitGC","-XX:+PrintGC","-XX:+PrintGCDateStamps","-XX:+PrintGCDetails","-XX:+PrintGCTimeStamps","-Xloggc:/app/dump/gclog","-XX:+HeapDumpOnOutOfMemoryError","-XX:HeapDumpPath=/app/dump","-jar","./server/runtime/caf-bootstrap.jar","--spring.config.location=./server/runtime/"]
buildx build -t zhaobsh:arm64 --platform=linux/arm64 -o type=docker .
buildx build -t zhaobsh:amd64 --platform=linux/amd64 -o type=docker .
我在arm上面搭建的就不行没法运行amd64的
docker run -it zhaobsh:amd64
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
java: error while loading shared libraries: libpthread.so.0: ELF load command alignment not page-aligned
然后 arm64自己的进行验证
可以直接push操作
buildx build -t harbor.xxxx.com/library/zhaobsh --platform=linux/arm,linux/arm64,linux/amd64 . --push
# 这个我还没测试
迁移测试
docker save zhaobsh:amd64 |gzip > zhaobsh_amd64.tgz
然后在amd64的机器上面进行验证.
也可以使用如下命令进行检查具体的架构信息:
[root@auto02 docker]# docker inspect zhaobsh:amd64 |grep Architecture
"Architecture": "amd64",
[root@auto02 docker]# docker inspect zhaobsh:arm64 |grep Architecture
"Architecture": "arm64",
[root@auto02 docker]#