You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/learn/develop/dockerfile.md
+19-13Lines changed: 19 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,11 +67,23 @@ __Note:__ You *don't* need to worry about ignoring `.git` as the builders alread
67
67
68
68
## Dockerfile templates
69
69
70
-
One of the goals of {{ $names.company.lower }} is code portability and ease of use, so you can easily manage and deploy a whole fleet of different devices. This is why Docker containers were such a natural choice. However, there are cases where Dockerfiles fall short and can't easily target multiple different device architectures.
70
+
Dockerfile templates are a balena-specific feature that allow our builders to substitute a value for one of the following variables at build time:
71
71
72
-
To allow our builders to build containers for multiple architectures from one code repository, we implemented simple Dockerfile templates.
72
+
{{> "deployment/build-variables" }}
73
+
74
+
The original purpose of these templates was to allow our builders to build containers for multiple architectures from one code repository when using the deprecated balenalib base images. For new projects, we recommend using standard Dockerfiles and either specifying the architecture in your FROM line, or utilizing base images that are published with the [multi-platform feature](https://docs.docker.com/build/building/multi-platform/). For example:
75
+
76
+
`FROM bh.cr/balenalabs/browser-aarch64`
77
+
78
+
Here, we are pulling an ARMv8 (aarch64) architecture-specific container image. This image can only be used for fleets with devices of that architecture.
79
+
80
+
`FROM debian:trixie`
81
+
82
+
This Debian Official Docker image is a multi-arch image instead. Upon build time, the balena builders would pull the correct architecture of the image based on the default device type of your fleet. This reduces complexity and provides a similar feature set to Dockerfile templates in the past.
73
83
74
-
It is now possible to define a `Dockerfile.template` file that looks like this:
84
+
It is possible to have different device types in the same fleet, as long as they have the same or compatible architectures. You need to ensure that your packages and modules are also available in that target architecture, otherwise, your application might throw errors or fail during runtime.
85
+
86
+
If you are still using balenalib base images for an existing project, you can use dockerfile templates as described below:
75
87
76
88
```Dockerfile
77
89
FROM {{ $names.base_images.lib }}/%%{{ $names.company.allCaps }}_MACHINE_NAME%%-node
@@ -83,22 +95,16 @@ COPY src/ /usr/src/app
83
95
CMD ["node", "/usr/src/app/main.js"]
84
96
```
85
97
86
-
This template will build and deploy a Node.js project for any of the devices supported by {{ $names.company.lower }}, regardless of whether the device architecture is [ARM][ARM-link] or [x86][x86-link].
87
-
In this example, you can see the build variable `%%{{ $names.company.allCaps }}_MACHINE_NAME%%`. This will be replaced by the machine name (i.e.: `raspberry-pi`) at build time. See below for a list of machine names.
88
-
89
-
The machine name is inferred from the device type of the fleet you are deploying on. So if you have a NanoPi Neo Air fleet, the machine name will be `nanopi-neo-air` and an `armv7hf` architecture base image will be built.
90
-
91
-
__Note:__ You need to ensure that your dependencies and Node.js modules are also multi-architecture, otherwise you will have a bad time.
98
+
This `dockerfile.template` file will build and deploy a Node.js project for any of the devices supported by {{ $names.company.lower }}, regardless of device architecture, whether is [ARM][ARM-link] or [x86][x86-link].
92
99
93
-
Currently our builder supports the following build variables:
100
+
In this example, the build variable `%%{{ $names.company.allCaps }}_MACHINE_NAME%%`. This will be replaced by the machine name (i.e.: `raspberry-pi`) at build time. Refer to [supported machine names and architectures][supported-devices].
94
101
95
-
{{> "deployment/build-variables" }}
102
+
The machine name is inferred from the device type of the fleet you are deploying on. So if you have a NanoPi Neo Air fleet, the machine name will be `nanopi-neo-air` and an `armv7hf` architecture base image will be built.
96
103
97
104
__Note:__ If your fleet contains devices of different types, the `%%{{ $names.company.allCaps }}_MACHINE_NAME%%` build variable **will not** evaluate correctly for all devices. Your fleet services are built once for all devices, and the `%%{{ $names.company.allCaps }}_MACHINE_NAME%%` variable will pull from the device type associated with the fleet, rather than the target device. In this scenario, you can use `%%{{ $names.company.allCaps }}_ARCH%%` to pull a base image that matches the shared architecture of the devices in your fleet.
98
105
99
106
If you want to see an example of build variables in action, have a look at this [basic openssh example]({{ $links.githubPlayground }}/balena-openssh).
100
107
101
-
Here are the [supported machine names and architectures][supported-devices].
102
108
103
109
## Multiple Dockerfiles
104
110
@@ -214,4 +220,4 @@ The {{ $names.company.lower }} Supervisor requires that the directory `/tmp/bale
0 commit comments