# Creating custom base images

**URL:** <https://forums.balena.io/t/creating-custom-base-images/1641>\
**Category:** Product support\
**Tags:** raspberrypi3, docker\
**Created:** [August 11, 2017, 3:13pm UTC](https://forums.balena.io/t/creating-custom-base-images/1641 "2017-08-11T15:13:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/michael/32/521_2.png) [@Michael](https://forums.balena.io/u/Michael)\
**Post date:** [August 11, 2017, 3:13pm UTC](https://forums.balena.io/t/creating-custom-base-images/1641/1 "2017-08-11T15:13:41Z")

</div>

I try to create my own base images and I have one question and two problems regarding that.

1. A question, out of idle curiosity: how does Dockerfile with `FROM resin/raspberrypi3-debian` manages to build on a mac? I was really surprised that it worked on my machine (because arm and x86 are quite different beasts).

2. Why the same Dockerfile that worked locally fails to build an image on docker cloud services (both hub and cloud):

```auto
Building in Docker Cloud's infrastructure...
Cloning into '.'...
Warning: Permanently added the RSA host key for IP address '104.192.143.3' to the list of known hosts.
Reset branch 'master'
Your branch is up-to-date with 'origin/master'.
KernelVersion: 4.4.0-87-generic
Arch: amd64
BuildTime: 2017-03-28T19:26:53.326478373+00:00
ApiVersion: 1.27
Version: 17.03.1-ee-2
MinAPIVersion: 1.12
GitCommit: ad495cb
Os: linux
GoVersion: go1.7.5
Starting build of index.docker.io/vasin/vs-player:latest...
Step 1/7 : FROM resin/raspberrypi3-debian
---> 31724eed925c
Step 2/7 : RUN apt-get update && apt-get install -yq cmake build-essential
---> Running in 90170e50105f
standard_init_linux.go:178: exec user process caused "exec format error"
Removing intermediate container 90170e50105f
The command '/bin/sh -c apt-get update && apt-get install -yq cmake build-essential' returned a non-zero code: 1
ERROR: Build failed: The command '/bin/sh -c apt-get update && apt-get install -yq cmake build-essential' returned a non-zero code: 1
ERROR: Build failed with exit code 2
ERROR: Build in 'master' (7b8c52f1) failed in 0:01:45

```

Are there any workarounds? I’d prefer to just push code of my base image to repository and not to build and push docker image to docker cloud manually after that.

I’ve noticed that [https://hub.docker.com/r/resin/raspberrypi3-debian/](https://hub.docker.com/r/resin/raspberrypi3-debian/) is also not auto-built, so I suppose [resin.io](http://resin.io) team has the same problem.

1. How can I pull a private base image from Docker hub for [resin.io](http://resin.io) device? I was able to use a public image for that, now how do I tell resin my docker credentials?

---

<div class="post-metadata">

**Author:** ![craig-mulligan](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/craig-mulligan/32/18_2.png) [@craig-mulligan](https://forums.balena.io/u/craig-mulligan)\
**Post date:** [August 11, 2017, 4:07pm UTC](https://forums.balena.io/t/creating-custom-base-images/1641/2 "2017-08-11T16:07:45Z")

</div>

Hey Michael,

1. All resin-base images have a qemu binary which allows them to run on any host that has `binfmt_misc` setup and [docker for mac does](https://docs.docker.com/docker-for-mac/multi-arch/). `binfmt_misc` intercepts system calls to the kernal and uses qemu to emulate.

2. I’ve only ever built custom images locally, but it is possible to build them on CI servers if you use a resin image as a base, this is because there is a tool called [`Resin-xbuild`](https://docs.resin.io/runtime/resin-base-images/#resin-xbuild-qemu) it’s a script that replicates what binfmt\_misc does without having to touch the host system - more info [here](https://resin.io/blog/building-arm-containers-on-any-x86-machine-even-dockerhub/). You do however need to tell the tool which calls to intercept.

```auto
RUN ["cross-build-start"]
RUN apt-get install ...
RUN ["cross-build-end"]

```

Example [here](https://github.com/petrosagg/armv7hf-python-dockerhub).

[https://hub.docker.com/r/resin/raspberrypi3-debian/](https://hub.docker.com/r/resin/raspberrypi3-debian/) is built on a custom CI server, so as far as I know we don’t need this tool, @nghiant2710 could you confirm?

1. We currently don’t support build environment variables so there is no way to keep secrets in your build atm. A good work around is to build the image locally with our cli.  
The two commands you’ll need are:

- [resin build](https://docs.resin.io/tools/cli/#build-source-)
- [resin deploy](https://docs.resin.io/tools/cli/#deploy-60-appname-62-image-)

This is a little out of my wheel house so I’ll have to ask @nghiant2710 our base image expert to make sure everything I’ve said is up to date and accurate. I hope that explains things a little.
