Build Docker image for ARM architecture on Intel machine (Mac)

泄露秘密 提交于 2020-01-21 03:51:24

问题


I'd like to be able to build a Docker image for ARM from my Mac. I know I can run ARM containers on my Mac using QEMU but I can't figure out how to build for ARM.


回答1:


This is a little convoluted right now. I am sure it will be made easier by docker in the near future.

Basically you need to build a contained based on a container that has the qemu-arm-static binary in it already.

You can see how it is done by looking at Raspberry Pi base image w/qemu-arm-static which builds the images directly with travis.

What I did was basically on my raspberry pi build my base docker image with this binary added and push that to the docker-hub.

Once I have that image as my base I can build and run containers that are derived from it, including building new derived containers, on my OSX machines and then run it on my raspberry pi's unmodified.

On my raspberry pi I build an image using this Dockerfile. I am starting with hypriot's base alpine image. You should be able to use any base image you want.

FROM hypriot/rpi-alpine-scratch

RUN apk update && \
apk upgrade && \
apk add bash && \
rm -rf /var/cache/apk/*

COPY qemu-arm-static /usr/bin/qemu-arm-static

CMD ["/bin/bash"]

Once I push that to Dockerhub I know have a container I can build based on on my intel machines and run and build on my raspberry pi's.

The qemu-arm-static binary I got by launching a debian i386 docker container, installing qemu-user-static and copying the binary out.



来源:https://stackoverflow.com/questions/37281802/build-docker-image-for-arm-architecture-on-intel-machine-mac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!