error building mkfs-hostapp-native.bb recipe

I have cloned the repository:
git clone --recursive https://github.com/balena-os/balena-raspberrypi.git

And started the build:
./balena-yocto-scripts/build/barys -m "raspberrypi4-64"

I get the following error from the mkfs-hostapp-native recipe:

Initialising tasks: 100% |########################################################################################################################################################################| Time: 0:00:02
Sstate summary: Wanted 33 Local 2 Mirrors 0 Missed 31 Current 1863 (6% match, 98% complete)
NOTE: Executing Tasks
ERROR: mkfs-hostapp-native-1.0-r0 do_compile: ExecutionError('/home/ben.s/yocto/balena-raspberrypi/build/tmp/work/x86_64-linux/mkfs-hostapp-native/1.0-r0/temp/run.do_compile.185525', 1, None, None)
ERROR: Logfile of failure stored in: /home/ben.s/yocto/balena-raspberrypi/build/tmp/work/x86_64-linux/mkfs-hostapp-native/1.0-r0/temp/log.do_compile.185525
Log data follows:
| DEBUG: Executing shell function do_compile
| #1 [internal] load .dockerignore
| #1 transferring context: 2B done
| #1 DONE 0.0s
|
| #2 [internal] load build definition from Dockerfile
| #2 transferring dockerfile: 219B done
| #2 DONE 0.0s
|
| #3 [internal] load metadata for docker.io/library/debian:stretch
| #3 DONE 1.0s
|
| #4 [1/3] FROM docker.io/library/debian:stretch@sha256:c5c5200ff1e9c73ffbf188b4a67eb1c91531b644856b4aefe86a58d2f0cb05be
| #4 DONE 0.0s
|
| #5 [internal] load build context
| #5 transferring context: 334B done
| #5 DONE 0.0s
|
| #6 [2/3] RUN apt-get update && apt-get install -y     ca-certificates         iptables
| #6 CACHED
|
| #7 [3/3] COPY create.* /usr/bin/
| #7 CACHED
|
| #8 exporting to image
| #8 exporting layers done
| #8 writing image sha256:2bc0a7bcf745aa7803ff0e9217b5a49372770fd80470802682f65f9fe8afff81 done
| #8 DONE 0.0s
| Error response from daemon: invalid reference format
| WARNING: exit code 1 from a shell command.
ERROR: Task (/home/ben.s/yocto/balena-raspberrypi/build/../layers/meta-balena/meta-balena-common/recipes-containers/mkfs-hostapp-native/mkfs-hostapp-native.bb:do_compile) failed with exit code '1'
NOTE: Tasks Summary: Attempted 4445 tasks of which 4443 didn't need to be rerun and 1 failed.

Summary: 1 task failed:
  /home/ben.s/yocto/balena-raspberrypi/build/../layers/meta-balena/meta-balena-common/recipes-containers/mkfs-hostapp-native/mkfs-hostapp-native.bb:do_compile
Summary: There was 1 ERROR message, returning a non-zero exit code.
[000000038][LOG]Build for raspberrypi4-64 failed. Check failed log in build/tmp/log/cooker/raspberrypi4-64 .
[000000039][LOG]If build for raspberrypi4-64 succeeded, final image should have been generated here:
[000000039][LOG]   build/tmp/deploy/images/raspberrypi4-64/balena-image-raspberrypi4-64.balenaos-img
[000000039][LOG]Done.

I have debugged this issue and see that this line is the problem in recipe mkfs-hostapp-native.bb:
IMAGE_ID=$(DOCKER_API_VERSION=1.22 docker build ${B}/work | grep -o -E '[a-z0-9]{12}' | tail -n1)

Here IMAGE_ID remains empty and is not set correctly, even though the docker build command works correctly. I think it is because the docker build output is to stderr and not stdout.
I tried to redirect the output but encountered further errors.

My system:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.5 LTS
Release: 20.04
Codename: focal

My docker:
Docker version 23.0.0, build e92dd87

I have the same issue on balena-allwinner build. It was all good a couple of months ago.

I have changed this line to
IMAGE_ID=$(DOCKER_API_VERSION=1.22 docker build -q ${B}/work)
and it fix the issue

Hi,
We recommend build servers to use the same docker version that balenaOS is using, and that is currently vv20.10.x. Our build servers and development team uses that docker version, so please try downgrading to that.
We also provide a containerized build environment (see balena-yocto-scripts/balena-build.sh at master · balena-os/balena-yocto-scripts · GitHub) to isolate users from host dependencies which might be worth a try too.

I get the same error using balena-build.sh, can you confirm software specs of the build servers you use so I can replicate. Host OS, Docker Version etc

Sure, our build servers are currently running 18.04.6 LTS (Bionic Beaver) and Docker version 20.10.9.