问题
今天正好遇到一个问题,需要在我的台式机上为macos笔记本构建docker镜像,但是一开始使用docker buildx不能正常构建,报告exec /bin/sh: exec format error
错误,这该如何解决呢?
解决方案
经过搜索,build-linux-arm64-docker-image-on-linux-amd64-host给出了一个解决方案。不过方案里的参数有些老了,我做了些更新。
执行以下步骤即可
1 2 3 |
docker run --rm --privileged docker/binfmt:a7996909642ee92942dcd6cff44b9b95f08dad64 docker buildx create --use --name multi-arch-builder |
然后使用docker buildx ls
发现已经有了linux/arm64这个架构了
验证
尝试执行arm64架构构建,执行成功
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
> docker buildx build --platform linux/arm64 -t sharpbai/nsenter1 . WARNING: No output specified with docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load [+] Building 40.0s (11/11) FINISHED => [internal] booting buildkit 12.9s => => pulling image moby/buildkit:buildx-stable-1 12.0s => => creating container buildx_buildkit_multi-arch-builder0 0.9s => [internal] load build definition from Dockerfile 0.1s => => transferring dockerfile: 275B 0.0s => [internal] load .dockerignore 0.1s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/alpine:edge 4.1s => [auth] library/alpine:pull token for registry-1.docker.io 0.0s => [build 1/4] FROM docker.io/library/alpine:edge@sha256:2d01a16bab53a8 1.1s => => resolve docker.io/library/alpine:edge@sha256:2d01a16bab53a8405876 0.0s => => sha256:421b24ebf09e91eab279ebb2ebcc743eb913939335 3.32MB / 3.32MB 0.8s => => extracting sha256:421b24ebf09e91eab279ebb2ebcc743eb913939335edce7 0.1s => [internal] load build context 0.1s => => transferring context: 1.32kB 0.0s => [build 2/4] RUN apk update && apk add build-base 18.6s => [build 3/4] COPY nsenter1.c ./ 0.5s => [build 4/4] RUN cc -Wall -static nsenter1.c -o /usr/bin/nsenter1 1.1s => [stage-1 1/1] COPY --from=BUILD /usr/bin/nsenter1 /usr/bin/nsenter1 0.3s |