balena preload with Gitlab CI


I’d like to use Gitlab CI (with the Gitlab shared runners) to create images with preloaded releases. I came to the following .gitlab.yml file

  - build

  image: node:12.22.5
  stage: build
    - linux
    - docker
    DOCKER_HOST: tcp://docker:2375
    - docker:dind
    - wget -q && unzip -q -d . && rm
    - export PATH=$PATH:$PWD/balena-cli
    - balena login --credentials --email $BALENA_LOGIN_EMAIL --password $BALENA_LOGIN_PASSWORD
    - balena os download jn30b-nano -o $PWD/balena.img --version $BALENA_OS_REVISION
    - balena preload --dockerHost docker --dockerPort 2375 $PWD/balena.img --fleet $BALENA_FLEET --commit current

But I got the following output and the error in the balena preload

$ balena os download jn30b-nano -o $PWD/balena.img --version $BALENA_OS_REVISION
Getting device operating system for jn30b-nano
Downloading Device OS 2.75.0+rev1 [                        ] 0% eta 3m52s

Downloading Device OS 2.75.0+rev1 [========================] 100% eta 0s
The image was downloaded successfully
$ balena preload --dockerHost docker --dockerPort 2375 $PWD/balena.img --fleet $BALENA_FLEET --commit current
Building Docker preloader image. [                        ] 0%

Building Docker preloader image. [========================] 100%
Additional information may be available with the `--debug` flag.
For further help or support, visit:

This seems to be related to this thread: Balena Preload on Github Actions
But I couldn’t still solve my problem.

Any help how to solve this networking issue?

Hello there, can you try running the preload command with debugging enabled? You can add the --debug flag to the command or prepend the env var DEBUG=1 balena preload .... That might give us more information on what is going wrong.

Checking the thread you linked, it seems docker-in-docker is not supported on GitHub actions at the moment. I tried searching for GitLab support but couldn’t find anything that claimed support for it so my guess is it’s the same. DinD is required for preloading. However this user has made preloading work on actions with a slightly different approach: Balena Preload on Github Actions - #15 by pcorbel
I suggest you take a look at it and let us know how it goes!

The output with --debug in the balena preload command

$ balena preload --debug --dockerHost docker --dockerPort 2375 $PWD/balena.img --fleet $BALENA_FLEET --commit current

[282]([debug] new argv=[/builds/romain.bethenod/system-preparation/balena-cli/balena,/snapshot/versioned-source/bin/balena,preload,--dockerHost,docker,--dockerPort,2375,/builds/romain.bethenod/system-preparation/balena.img,--fleet,Romain,--commit,current] length=12

[283]([debug] Deprecation check: 0.00056 days since last npm registry query for next major version release date.

[284]([debug] Will not query the registry again until at least 7 days have passed.

[285]( Docker preloader image. [ ] 0%


[287]( Docker preloader image. [=== ] 12%

[288]( 1/7 : FROM alpine:3.12

[289]( ---> 13621d1b12d4


[291]( Docker preloader image. [====== ] 25%

[292]( 2/7 : WORKDIR /usr/src/app

[293]( ---> Running in e4753602c7b3

[294]( intermediate container e4753602c7b3

[295]( ---> d1715e469a99


[297]( Docker preloader image. [========= ] 37%

[298]( 3/7 : RUN apk add --no-cache curl py3-pip parted btrfs-progs util-linux sfdisk file coreutils sgdisk e2fsprogs-extra docker

[299]( ---> Running in e25d42364746



[302]( Installing libblkid (2.35.2-r0)

[303]( Installing lzo (2.10-r2)

[304]( Installing libuuid (2.35.2-r0)

[305]( Installing zstd-libs (1.4.9-r0)

[306]( Installing btrfs-progs (5.6.1-r0)

[307]( Installing libacl (2.2.53-r0)

[308]( Installing libattr (2.4.48-r0)

[309]( Installing coreutils (8.32-r0)

[310]( Installing ca-certificates (20191127-r4)

[311]( Installing nghttp2-libs (1.41.0-r0)

[312]( Installing libcurl (7.78.0-r0)

[313]( Installing curl (7.78.0-r0)

[314]( Installing libseccomp (2.4.4-r0)

[315]( Installing runc (1.0.0_rc95-r0)

[316]( Installing containerd (1.4.4-r0)

[317]( Installing libmnl (1.0.4-r0)

[318]( Installing libnftnl-libs (1.1.6-r0)

[319]( Installing iptables (1.8.4-r2)

[320]( Installing tini-static (0.19.0-r0)

[321]( Installing device-mapper-libs (2.02.186-r1)

[322]( Installing docker-engine (20.10.3-r0)

[323]( Installing docker-cli (20.10.3-r0)

[324]( Installing docker (20.10.3-r0)

[325]( docker-20.10.3-r0.pre-install

[326]( Installing libcom_err (1.45.6-r0)

[327]( Installing e2fsprogs-libs (1.45.6-r0)

[328]( Installing e2fsprogs (1.45.6-r0)

[329]( Installing e2fsprogs-extra (1.45.6-r0)

[330]( Installing libmagic (5.38-r0)

[331]( Installing file (5.38-r0)

[332]( Installing ncurses-terminfo-base (6.2_p20200523-r0)

[333]( Installing ncurses-libs (6.2_p20200523-r0)

[334]( Installing readline (8.0.4-r0)

[335]( Installing parted (3.3-r0)

[336]( Installing libbz2 (1.0.8-r1)

[337]( Installing expat (2.2.9-r1)

[338]( Installing libffi (3.3-r2)

[339]( Installing gdbm (1.13-r1)

[340]( Installing xz-libs (5.2.5-r0)

[341]( Installing sqlite-libs (3.32.1-r1)

[342]( Installing python3 (3.8.10-r0)

[343]( Installing py3-appdirs (1.4.4-r1)

[344]( Installing py3-ordered-set (4.0.1-r0)

[345]( Installing py3-parsing (2.4.7-r0)

[346]( Installing py3-six (1.15.0-r0)

[347]( Installing py3-packaging (20.4-r0)

[348]( Installing py3-setuptools (47.0.0-r0)

[349]( Installing py3-chardet (3.0.4-r4)

[350]( Installing py3-idna (2.9-r0)

[351]( Installing py3-certifi (2020.4.5.1-r0)

[352]( Installing py3-urllib3 (1.25.9-r0)

[353]( Installing py3-requests (2.23.0-r0)

[354]( Installing py3-msgpack (1.0.0-r0)

[355]( Installing py3-lockfile (0.12.2-r3)

[356]( Installing py3-cachecontrol (0.12.6-r0)

[357]( Installing py3-colorama (0.4.3-r0)

[358]( Installing py3-distlib (0.3.0-r0)

[359]( Installing py3-distro (1.5.0-r1)

[360]( Installing py3-webencodings (0.5.1-r3)

[361]( Installing py3-html5lib (1.0.1-r4)

[362]( Installing py3-pytoml (0.1.21-r0)

[363]( Installing py3-pep517 (0.8.2-r0)

[364]( Installing py3-progress (1.5-r0)

[365]( Installing py3-toml (0.10.1-r0)

[366]( Installing py3-retrying (1.3.3-r0)

[367]( Installing py3-contextlib2 (0.6.0-r0)

[368]( Installing py3-pip (20.1.1-r0)

[369]( Installing libfdisk (2.35.2-r0)

[370]( Installing libsmartcols (2.35.2-r0)

[371]( Installing sfdisk (2.35.2-r0)

[372]( Installing libgcc (9.3.0-r2)

[373]( Installing popt (1.16-r7)

[374]( Installing libstdc++ (9.3.0-r2)

[375]( Installing sgdisk (1.0.6-r0)

[376]( Installing blkid (2.35.2-r0)

[377]( Installing libcap-ng (0.7.10-r1)

[378]( Installing setpriv (2.35.2-r0)

[379]( Installing libmount (2.35.2-r0)

[380]( Installing findmnt (2.35.2-r0)

[381]( Installing mcookie (2.35.2-r0)

[382]( Installing hexdump (2.35.2-r0)

[383]( Installing lsblk (2.35.2-r0)

[384]( Installing cfdisk (2.35.2-r0)

[385]( Installing util-linux (2.35.2-r0)

[386]( busybox-1.31.1-r20.trigger

[387]( ca-certificates-20191127-r4.trigger

[388]( 380 MiB in 97 packages

[389]( intermediate container e25d42364746

[390]( ---> e5e3db540a09


[392]( Docker preloader image. [============ ] 50%

[393]( 4/7 : COPY requirements.txt ./

[394]( ---> 3b88cca001a8


[396]( Docker preloader image. [=============== ] 62%

[397]( 5/7 : RUN pip3 install --no-cache-dir -r requirements.txt

[398]( ---> Running in 3c6fb41dcde2

[399]( sh==1.12.14

[400]( Downloading sh-1.12.14-py2.py3-none-any.whl (38 kB)

[401]( retry==0.9.2

[402]( Downloading retry-0.9.2-py2.py3-none-any.whl (8.0 kB)

[403]( decorator>=3.4.2

[404]( Downloading decorator-5.0.9-py3-none-any.whl (8.9 kB)

[405]( py<2.0.0,>=1.4.26

[406]( Downloading py-1.10.0-py2.py3-none-any.whl (97 kB)

[407]( collected packages: sh, decorator, py, retry

[408]( installed decorator-5.0.9 py-1.10.0 retry-0.9.2 sh-1.12.14

[409]( intermediate container 3c6fb41dcde2

[410]( ---> 916e53740719


[412]( Docker preloader image. [================== ] 75%

[413]( 6/7 : COPY src/ ./

[414]( ---> 69152afbc9bc


[416]( Docker preloader image. [===================== ] 87%

[417]( 7/7 : CMD ["python3", "/usr/src/app/"]

[418]( ---> Running in d80404fb9d2a

[419]( intermediate container d80404fb9d2a

[420]( ---> ef40772206bb

[421]( built ef40772206bb

[422]( tagged balena/balena-preload:latest


[424]( Docker preloader image. [========================] 100%

[425]( for Docker to start...

[426]( started

[427]( splash image alone

[428]( partition n°16 of /img/balena.img

[429]( ext4 filesystem of partition n°16 of /img/balena.img using /dev/loop0

[430]( system OK

[431]( for Docker to start...

[432]( started

[433]( connect ECONNREFUSED

[434]( connect ECONNREFUSED

[435]( at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14)

[436]( previous event:

[437]( at runCallback (timers.js:705:18)

[438]( at tryOnImmediate (timers.js:676:5)

[439]( at processImmediate (timers.js:658:5)

[440]( at process.topLevelDomainCallback (domain.js:126:23)

[441]( previous event:

[442]( at preload.Bluebird.resolve.then (/snapshot/versioned-source/node_modules/balena-preload/build/preload.js:751:28)

[443]( further help or support, visit:


To my understanding docker in docker is supported on Gitlab. You can take a look here: Use Docker to build Docker images | GitLab

Do you mean here to get a Gitlab runner which can execute docker commands directly? Yes sure it should work but how to get one from the Gitlab shared runner? I’d strongly prefer to not have to maintain a server just for a job.

Hello @Romain ,

The link you shared has a few examples with specific docker images ( docker:19.03.12)and configurations (tls_verify). Have you tried using a similar config to run the preload?


exactly I tried to do it. The .gitlab.yml is provided in the first message. As you can see, some part are working like Building Docker preloader image. Then it cannot connect to the port. If you have an example of .gitlab.yml where it works (with tls_verify), I will for sure take a look.

Hello @Romain sorry for the late answer on this!

Did you make it run? what’s the situation of this nowadays?

Let us know if we can help you more!

For Gitlab (on the shared Gitlab runners), with the few answer I was still unable to make it work. If you can test directly on Gitlab and provide something more specific in order to make it work, I can try to integrate it into our project.

Hello, I don’t see any reason why preload would be unable to run on a shared Gitlab runner, but I’ve never tried it myself. We mostly use Github at balena and I’ve only run one personal project on shared Gitlab runners.

I skimmed your job configuration and I don’t see any obvious issues. I checked that the jn30b-nano device type does use the more modern overlay2 storage, so it shouldn’t be a matter of the runner or dind image dropping support for AUFS.

Have you tried a more recent release of the balena CLI? There have been a number of changes to preload since v12.47.0 that would be worth picking up.