Is there a way to specify which docker-compose file to use while deploying with the CLI?

Hi everyone,

I’m trying to create a multi-architecture deployment system. I have an application with several sub-systems, each with its own dockerfile. Since it’s a multi-container build, I have a docker-compose.yaml in the project root. This sums up my project structure:

_ Subsystem1/Dockerfile
_ Subsystem2/Dockerfile
_ Subsystem3/Dockerfile
_ docker-compose.yaml

The whole point is that this application must run on both arm64 and amd64 (so it’s a multi-arch).
All my dockerfiles depends on dotnet core, which doesn’t seem to support multi-arch, therefore I’m forced to use an architecture-specific base image in the dockerfiles which leads to having 2 dockerfile for each sub-system and two docker-compose..yaml file.

Having two file for each microservice introduces some maintenance problem, but I’m willing to accept it. The problem is balena deploy doesn’t seem to have an argument or a way to specify which docker-compose file to use; it simply search for a file named literally “docker-compose.yaml” and, if it doesn’t find it, supposes it’s a single container application.

Is there a way to specify which compose file to use? Am I addressing this problem in the wrong way? Is there an alternative solution for it? Thanks!

Hey Andrea!

Have a read about a dockerfile templates: Define a container - Balena Documentation
Those allow you to put something like the following in your dockerfile(s):

FROM balenalib/%%BALENA_MACHINE_NAME%%-debian-dotnet:3.1-aspnet-run

When the application then builds after you do your balena push command, the builder will resolve the template variables and pull the correct base image for you. You can also use BALENA_ARCH in the same way.


Here’s a full example, in case it helps:

For reference in the multiple docker-compose files: Add ability to select a docker-compose file · Issue #1142 · balena-io/balena-cli · GitHub

Hi @phil-d-wilson,
sorry for the late feedback, but we’ve been a little busy on other projects those weeks.

We tested the suggested solution and I confirm we are now able to successfully deploy the same codebase to different applications (and therefore devices) without any script or manual edit.
We just changed the base image to the balenalib registry and used the .template dockerfile.

Thanks a lot!

1 Like