Local Docker Development Workflow and docker-compose.override.yml behavior For Balena?

TLDR: Does Balena Engine / OS recognize docker-compose.override.yml file or is it disregarded? Is anyone else out there developing Balena applications locally on their laptop using docker before testing on hardware via livepush? Appreciate any feedback on best workflow.

Background:
I’m working on a better TDD workflow for a microservice architecture running on BalenaFin but of which the majority of containers do not require hardware interaction. I’ve been playing around with running containers locally using docker with huge improvements on speed running tests and simply not having to deal with livepush connection issues which happen frequently for us. But, how to switch between both local docker engine and Balena on the Fin without constantly changing production compose files on feature branches has been a topic of investigation, especially as I’m building this workflow for our entire team.

Conflicts with Balena Engine:

Balena does not yet support alternate compose files
My current understanding is that switching between compose configurations is not available with Balena Engine. We do not have the option to pass an alternative compose file as an argument for Balena build/push such as docker-compose.production.yml or docker-compose.development.yml.

Balena does not allow build-arg before from
We also do not have the option of using BUILD-ARG before FROM in container docker files so we cannot template the base image.

Balena only supports %%BALENA_MACHINE_NAME%%
I do understand that Balena has support for templating architectures in the dockerfile. However, my assumption is that this only works when using balena, which if I was to use locally on my laptop would require VirtualBox VM which seems overkill since everyone on our team already has docker engine and docker desktop installed on thier computers. Ideally we could simply docker compose build up and start developing and running tests on containers.

Best Solution So Far:

My best solution has been to use docker-compose.override.yml to adjust my compose file locally on my development laptop running docker. Pytest runs ~5x faster on amd64 vs fincm3 which is amazing. From testing, I believe that Balena Engine does not recognize the docker override file and so this actually works out pretty well for local development and I can also instantly push to our local mode device at anytime via livepush without conflict. But I’d be curious to hear from the Balena team if ignoring the override file is a predictable behavior of Balena Engine/OS?

I’ve detailed an example docker-compose and docker-compose.ovveride setup below. My current thought is to keep a docker override template file in our repo that developers can customize during feature development untracked in their local feature branch. I have to believe folks out there are doing this already, but could not find specific examples from the forum.

Example Setup:

docker-compose.yml

version: '2'
services: 

redis:
    build:
        context: ./redis
        dockerfile: Dockerfile_fincm3
    expose:
      - "6379"
    ports:
      - "6379:6379"
    volumes:
      - 'redis-data:/redis-data'
 
my-service:
    build:
        context: ./my-service
        dockerfile: Dockerfile_fincm3
    expose:
       - "80"
    ports:
      - "84:80"
    depends_on:
      - redis

docker-compose.override.yml

version: '2'
services:

  my-service:
    build:
        # Change to dockerfile using
        # generic-x86 base image..
        dockerfile: Dockerfile_x86

    volumes:
      # bind volume for local development
      - ./map-service2:/usr/src/app

  redis:
    build:
        # Change to dockerfile using
        # amd64 base image..
        dockerfile: Dockerfilex_86

That’s basically how I ended up going, having a parallel file for local dev. I had quite a lot of differences though, so instead of using the override file I have a separate docker-compose file called docker-compose-dev.yml and start it with docker-compose -f docker-compose-dev.yml up.

There is some discussion on override files here too: Add ability to select a docker-compose file · Issue #1142 · balena-io/balena-cli · GitHub. Worth reading it all as there is a ‘shallow merge’ function, which may be helpful, but also raises a potential compatibility conflict if you use standard naming conventions.

Hey, Alex, I do not believe there is support for docker-compose.override.yml or any plans to implement support for it (unless there is user demand), so I think your solution should be fine, if you are just running some tests and don’t need a fully virtualized Balena OS environment (otherwise, see here).

Furthermore, when using docker-compose, you have the full features of docker-compose for extending as seen here: Share Compose configurations between files and projects | Docker Documentation .

This means you could do something like docker-compose -f docker-compose.yml -f docker-compose.dev.yml up as well, giving you even more flexibility.

Balena only supports a subset of these features for the sake of simplicity.

Also, it should be noted that, without the fully virtualized environment, tests that run in the docker containers might not work in the BalenaOS containers, so you should be sure to run in both before deployment to test in on the actual hardware to be safe.