# Why does a build fail on Docker Hub but not on macOS?

**URL:** <https://forums.balena.io/t/why-does-a-build-fail-on-docker-hub-but-not-on-macos/740>\
**Category:** Product support\
**Created:** [April 5, 2017, 8:10pm UTC](https://forums.balena.io/t/why-does-a-build-fail-on-docker-hub-but-not-on-macos/740 "2017-04-05T20:10:44Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulmuller](https://avatars.discourse-cdn.com/v4/letter/p/ed655f/32.png) [@paulmuller](https://forums.balena.io/u/paulmuller)\
**Post date:** [April 5, 2017, 8:10pm UTC](https://forums.balena.io/t/why-does-a-build-fail-on-docker-hub-but-not-on-macos/740/1 "2017-04-05T20:10:44Z")

</div>

I have a Dockerfile starting like this:

```
FROM resin/rpi-raspbian

RUN apt-get update && apt-get install -y git ...

```

This works fine on the Pi but it fails on Docker Hub with

> “exec format error”

I get it, resin/rpi-raspbian requires ARM hardware but Docker Hub is x86.

1. Why does `docker build .` NOT fail on macOS then?
2. Is there a way to write the Dockerfile so that it builds both on the Pi _and_ on Docker Hub?

---

<div class="post-metadata">

**Author:** ![brownjohnf](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/brownjohnf/32/142_2.png) [@brownjohnf](https://forums.balena.io/u/brownjohnf)\
**Post date:** [April 5, 2017, 8:16pm UTC](https://forums.balena.io/t/why-does-a-build-fail-on-docker-hub-but-not-on-macos/740/2 "2017-04-05T20:16:42Z")

</div>

I have no idea why your build worked on macOS, because as far as I know it shouldn’t. In terms of creating cross-platform Dockerfiles, the best reference is this blog post by Petros: [https://resin.io/blog/building-arm-containers-on-any-x86-machine-even-dockerhub/](https://resin.io/blog/building-arm-containers-on-any-x86-machine-even-dockerhub/)

---

<div class="post-metadata">

**Author:** ![paulmuller](https://avatars.discourse-cdn.com/v4/letter/p/ed655f/32.png) [@paulmuller](https://forums.balena.io/u/paulmuller)\
**Post date:** [April 5, 2017, 8:27pm UTC](https://forums.balena.io/t/why-does-a-build-fail-on-docker-hub-but-not-on-macos/740/3 "2017-04-05T20:27:42Z")

</div>

I didn’t expect it to run on macOS either. That’s why I didn’t initially believe “exec format error” in my case be an architecture issue even though all internet resources I found pointed into that direction.

I had found Petros’ post as well and I now understand (I believe) what `RUN ["cross-build-start"]` does. I’m reasonable certain it would make the build run on Docker Hub but what happens if it runs on the Pi?

---

<div class="post-metadata">

**Author:** ![brownjohnf](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/brownjohnf/32/142_2.png) [@brownjohnf](https://forums.balena.io/u/brownjohnf)\
**Post date:** [April 5, 2017, 8:28pm UTC](https://forums.balena.io/t/why-does-a-build-fail-on-docker-hub-but-not-on-macos/740/4 "2017-04-05T20:28:53Z")

</div>

I’m not sure. I think we’d need @petrosagg to chime in on that.

---

<div class="post-metadata">

**Author:** ![paulmuller](https://avatars.discourse-cdn.com/v4/letter/p/ed655f/32.png) [@paulmuller](https://forums.balena.io/u/paulmuller)\
**Post date:** [April 5, 2017, 8:48pm UTC](https://forums.balena.io/t/why-does-a-build-fail-on-docker-hub-but-not-on-macos/740/5 "2017-04-05T20:48:31Z")

</div>

I still need to get back to the drawing board (i.e. read the article again) because I was expecting `cross-build-start` to be available in resin/rpi-raspbian but that was a wrong assumption.

---

<div class="post-metadata">

**Author:** ![imrehg](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/imrehg/32/36_2.png) [@imrehg](https://forums.balena.io/u/imrehg)\
**Post date:** [April 5, 2017, 10:27pm UTC](https://forums.balena.io/t/why-does-a-build-fail-on-docker-hub-but-not-on-macos/740/6 "2017-04-05T22:27:46Z")

</div>

Hey, do you have `qemu-system-arm` set up on your Mac? That would explain why it would have worked, the system would emulate ARM for those base images. For example I have that set up on my local Linux machine, and can cross compile locally these containers (that that will run on the original architecture).

Looking into the blogpost, it seems like the key is using the `armv7hf-debian-qemu` base image, which includes that qemu executable and the cross-compile setup.

> **[balena-io-library/armv7hf-debian-qemu](https://github.com/balena-io-library/armv7hf-debian-qemu)**
>
> An ARM base image that includes the modified QEMU from https://github.com/resin-io/qemu/commits/qemu-execve - balena-io-library/armv7hf-debian-qemu

I’d think you’d need to adapt that repo to your need, guessing you can just replace `FROM resin/armv7hf-debian:jessie` with the base you’d like `FROM resin/rpi-raspbian` or `FROM resin/raspberrypi3-debian` for example, and you could create thus a relevant `...-qemu` version that you can use for your own project.

It’s a guess, but I’m more confident in it than not that it would work 💰

The usual resin base images are not setup like this, imho, because 1) they would ship with more binary that they really need and most of the time that’s not great; 2) if there’s external `qemu-system-arm` set up then the container can be built on other architectures as well (as the [resin.io](http://resin.io) builders, and as opposed to the DockerHub builders).

---

<div class="post-metadata">

**Author:** ![paulmuller](https://avatars.discourse-cdn.com/v4/letter/p/ed655f/32.png) [@paulmuller](https://forums.balena.io/u/paulmuller)\
**Post date:** [April 6, 2017, 6:03am UTC](https://forums.balena.io/t/why-does-a-build-fail-on-docker-hub-but-not-on-macos/740/7 "2017-04-06T06:03:47Z")

</div>

> [@imrehg](#):
>
> do you have qemu-system-arm set up on your Mac? That would explain why it would have worked,

I wouldn’t know - certainly didn’t do that on purpose. However, when I asked [Spotlight](https://en.wikipedia.org/wiki/Spotlight_(software)) for “qemu” it turned up [a MacPorts port](https://github.com/macports/macports-ports/blob/master/emulators/qemu/Portfile) that some other piece of software must have installed several months ago.

Great, one mystery unraveled, thanks.

---

<div class="post-metadata">

**Author:** ![imrehg](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/imrehg/32/36_2.png) [@imrehg](https://forums.balena.io/u/imrehg)\
**Post date:** [April 6, 2017, 4:53pm UTC](https://forums.balena.io/t/why-does-a-build-fail-on-docker-hub-but-not-on-macos/740/8 "2017-04-06T16:53:21Z")

</div>

Actually, @paulmuller, after some more input from @shaunmulligan, it seems that the reason why your Docker setup can cross-build on Mac is because Docker for Mac has multi-CPU support, including ARM:

> **[Leverage multi-CPU architecture support](https://docs.docker.com/docker-for-mac/multi-arch/)**
>
> Docker images can support multiple architectures, which means that a single image may contain variants for different architectures, and sometimes for different operating systems, such as Windows. When running an...

So that’s really the mystery unraveled 🙂

* * *

Regarding cross-building in general, I’ve took the original repo linked above, and tried setting up with a different base image (`raspberrypi3-debian`), the result indeed just works:

> **[imrehg/raspberrypi3-debian-qemu](https://github.com/imrehg/raspberrypi3-debian-qemu)**
>
> Automated Raspberry Pi 3 Debian image. Contribute to imrehg/raspberrypi3-debian-qemu development by creating an account on GitHub.

The automated build is then at [https://hub.docker.com/r/imrehg/raspberrypi3-debian-qemu/](https://hub.docker.com/r/imrehg/raspberrypi3-debian-qemu/) That you could then use as the base of another image, that you can create your own application base image, for example here I installed `python` and `numpy`:

> **[imrehg/raspberrypi3-debian-qemu-numpy](https://github.com/imrehg/raspberrypi3-debian-qemu-numpy)**
>
> Cross-compile on DockerHub for RPi3 + Debian + numpy - imrehg/raspberrypi3-debian-qemu-numpy

The automated build of that is then at [https://hub.docker.com/r/imrehg/raspberrypi3-debian-qemu-numpy/](https://hub.docker.com/r/imrehg/raspberrypi3-debian-qemu-numpy/) and could be used by a `Dockerfile` (this one deployed on [resin.io](http://resin.io) onto a device) as like this, installing the `nose` python test suite and running it on the device:

```auto
FROM imrehg/raspberrypi3-debian-qemu-numpy

RUN pip3 install nose

CMD python3 -c 'import numpy; numpy.test("full");' && while : ; do echo "Idling..."; sleep 600; done

```

All these are just some examples, that the original method works, and some extra hints on how to use them.

* * *

On the other hand, if you can build your containers locally as well with `docker build` (without needing to do automated builds), the resulting image you can `docker push` to DockerHub, and can work from there similarly, without messing with all these cross-compilation steps at all!

What kind of use case you have in mind? Why would you prefer to do builds on DockerHub?

---

<div class="post-metadata">

**Author:** ![paulmuller](https://avatars.discourse-cdn.com/v4/letter/p/ed655f/32.png) [@paulmuller](https://forums.balena.io/u/paulmuller)\
**Post date:** [April 7, 2017, 6:07am UTC](https://forums.balena.io/t/why-does-a-build-fail-on-docker-hub-but-not-on-macos/740/9 "2017-04-07T06:07:31Z")

</div>

Thanks a lot, really helpful.

> [@imrehg](#):
>
> What kind of use case you have in mind? Why would you prefer to do builds on DockerHub?

It’s all about the convenience that I get when done in combination with GitHub. From wherever I am I can simply push the Dockerfile to GitHub and then I’m done, or accept a PR and I’m done.

---

<div class="post-metadata">

**Author:** ![imrehg](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/imrehg/32/36_2.png) [@imrehg](https://forums.balena.io/u/imrehg)\
**Post date:** [April 7, 2017, 8:34am UTC](https://forums.balena.io/t/why-does-a-build-fail-on-docker-hub-but-not-on-macos/740/10 "2017-04-07T08:34:21Z")

</div>

When you mean you are done, what is the outcome that you mean? Are you trying to integrate (custom) base images with DockerHub like this, or are you trying to integrate deploying to [resin.io](http://resin.io) devices some way easier?

---

<div class="post-metadata">

**Author:** ![paulmuller](https://avatars.discourse-cdn.com/v4/letter/p/ed655f/32.png) [@paulmuller](https://forums.balena.io/u/paulmuller)\
**Post date:** [April 7, 2017, 8:42am UTC](https://forums.balena.io/t/why-does-a-build-fail-on-docker-hub-but-not-on-macos/740/11 "2017-04-07T08:42:47Z")

</div>

By “I’m done” I meant that I didn’t have to worry about building the image. I provide images for the general public on DockerHub based on Dockerfiles in public GitHub repositories. Some of those are for the Raspberry Pi. So, basically I’ve got two options if I don’t want to build images manually:

- enable cross-builds on DockerHub, requires modifications to the Dockerfile as discussed above
- integrate Travis CI (or similar) through GitHub hooks, Travis would do the cross-build and push to DockerHub

---

<div class="post-metadata">

**Author:** ![imrehg](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/imrehg/32/36_2.png) [@imrehg](https://forums.balena.io/u/imrehg)\
**Post date:** [April 7, 2017, 10:12am UTC](https://forums.balena.io/t/why-does-a-build-fail-on-docker-hub-but-not-on-macos/740/12 "2017-04-07T10:12:48Z")

</div>

I see, thanks. In our case I think we are cross-compiling locally and just pushing to DockerHub (we are doing a few thousand base images pretty much every day). DockerHub automatic build has the issue that long running builds are killed (e.g. I couldn’t get an image that has both `numpy` and `scipy` built, as the process was killed by DockerHub for taking too long). That can be a limitation for this setup.

Travis sounds interesting, because there you can modify your building host, and can add emulation in a way, that you don’t need to do any of these cross-building tricks (and ship those files with all of your containers). Was looking at for example this blogpost:

> **[Running Travis CI tests on ARM architecture](https://www.tomaz.me/2013/12/02/running-travis-ci-tests-on-arm.html)**
>
> Run Travis CI tests on ARM architecture using QEMU

It’s definitely interesting, and would love to hear what you make of it in the future, whichever path you choose!

---

<div class="post-metadata">

**Author:** ![paulmuller](https://avatars.discourse-cdn.com/v4/letter/p/ed655f/32.png) [@paulmuller](https://forums.balena.io/u/paulmuller)\
**Post date:** [April 7, 2017, 11:12am UTC](https://forums.balena.io/t/why-does-a-build-fail-on-docker-hub-but-not-on-macos/740/13 "2017-04-07T11:12:15Z")

</div>

I was looking at [https://github.com/hypriot/rpi-node/blob/master/.travis.yml](https://github.com/hypriot/rpi-node/blob/master/.travis.yml) for inspiration (they use your images).
