# Dockerfile templates

**URL:** <https://forums.balena.io/t/dockerfile-templates/181>\
**Category:** Product support\
**Created:** [November 3, 2015, 6:06pm UTC](https://forums.balena.io/t/dockerfile-templates/181 "2015-11-03T18:06:02Z")\
**Posts on this page:** 9\
**Page:** 1

<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:** [November 3, 2015, 6:06pm UTC](https://forums.balena.io/t/dockerfile-templates/181/1 "2015-11-03T18:06:02Z")

</div>

Hey everyone,

We released this feature sometime ago but until now haven’t officially announced it.

Dockerfile templates allow you to push variables to our resin builders. Current available variables are `RESIN_ARCH` and `RESIN_MACHINE_NAME`.

What this allows you to do is push your repository to any application with any device type without having to change any code.

For example our current base-image naming scheme is: `<devicetype>-<language>` e.g. `raspberrypi-node`

Therefore we could use the `RESIN_MACHINE_NAME` variable to push apps to multiple applications without changing the device type. All we would need to do is adjust the `FROM` command and rename our `Dockerfile` to `Dockerfile.template` like so:

`FROM resin/%%RESIN_MACHINE_NAME%%-node`

Our builders then infer `RESIN_MACHINE_NAME` from what “device type” application you are pushing to. So if the resin remote you are pushing to is associated to an Intel Edison application, the machine name will be edison and an i386 architecture base image will be built.

You can read more about them in our [docs](http://docs.resin.io/#/pages/deployment/docker-templates.md)

If you’d like to see more Dockerfile variables let us know the usecase and we’d be happy to implement!

Happy Hacking!

---

<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:** [November 14, 2015, 9:20am UTC](https://forums.balena.io/t/dockerfile-templates/181/2 "2015-11-14T09:20:51Z")

</div>

So in this case this would work by pushing to multiple apps from the same git repo, right? The resin apps themselves are still single-device-type only.

---

<div class="post-metadata">

**Author:** ![alexandrosm](https://avatars.discourse-cdn.com/v4/letter/a/b19c9b/32.png) [@alexandrosm](https://forums.balena.io/u/alexandrosm)\
**Post date:** [November 14, 2015, 7:49pm UTC](https://forums.balena.io/t/dockerfile-templates/181/3 "2015-11-14T19:49:50Z")

</div>

That’s correct. For now 🙂

---

<div class="post-metadata">

**Author:** ![justin8](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/justin8/32/91_2.png) [@justin8](https://forums.balena.io/u/justin8)\
**Post date:** [March 17, 2016, 6:21am UTC](https://forums.balena.io/t/dockerfile-templates/181/4 "2016-03-17T06:21:25Z")

</div>

I tried to use this and received this error:

```auto
Step 1 : FROM resin/%%RESIN_MACHINE_NAME%%-node
       Error while processing push: Error: repository name component must match "[a-z0-9](?:-*[a-z0-9])*(?:[._][a-z0-9](?:-*[a-z0-9])*)*"

```

---

<div class="post-metadata">

**Author:** ![shaunmulligan](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/shaunmulligan/32/34_2.png) [@shaunmulligan](https://forums.balena.io/u/shaunmulligan)\
**Post date:** [March 17, 2016, 9:58am UTC](https://forums.balena.io/t/dockerfile-templates/181/5 "2016-03-17T09:58:36Z")

</div>

Hi @justin8, this error is normally because someone tries to use the templating `%%` symbols in a regular `Dockerfile`, unfortunately the templates only work if your file is named `Dockerfile.template` …In the future we will implement some logic to try catch these cases and build the correct dockerfile, but at the moment it results in this quiet ugly error.  
sorry for the inconvenience.  
cheers  
Shaun

---

<div class="post-metadata">

**Author:** ![justin8](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/justin8/32/91_2.png) [@justin8](https://forums.balena.io/u/justin8)\
**Post date:** [March 18, 2016, 2:52am UTC](https://forums.balena.io/t/dockerfile-templates/181/6 "2016-03-18T02:52:56Z")

</div>

Ah, I skimmed the docs and didn’t notice the .template extension. Working well now. Thanks

---

<div class="post-metadata">

**Author:** ![winstonford](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/winstonford/32/925_2.png) [@winstonford](https://forums.balena.io/u/winstonford)\
**Post date:** [April 28, 2018, 2:32am UTC](https://forums.balena.io/t/dockerfile-templates/181/7 "2018-04-28T02:32:40Z")

</div>

How do I access and RESIN\_ARCH and RESIN\_MACHINE\_NAME in a conainer?

In a bash script running in my main container, I can echo $RESIN\_DEVICE\_UUID and $RESIN\_DEVICE\_NAME\_AT\_INIT, but $RESIN\_MACHINE\_NAME and $RESIN\_ARCH return nothing.

---

<div class="post-metadata">

**Author:** ![jgentes](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/jgentes/32/1595_2.png) [@jgentes](https://forums.balena.io/u/jgentes)\
**Post date:** [April 30, 2018, 10:24pm UTC](https://forums.balena.io/t/dockerfile-templates/181/8 "2018-04-30T22:24:20Z")

</div>

@winstonford would `RESIN_DEVICE_TYPE` work? That will tell you `intel-nuc` or `raspberrypi3`.

Otherwise there may be a way to use a docker-compose file to push arguments into a container during the docker build process.

---

<div class="post-metadata">

**Author:** ![winstonford](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/winstonford/32/925_2.png) [@winstonford](https://forums.balena.io/u/winstonford)\
**Post date:** [April 30, 2018, 11:56pm UTC](https://forums.balena.io/t/dockerfile-templates/181/9 "2018-04-30T23:56:07Z")

</div>

Thx @jgentes , that works.
