Issue building an LXC container within a pipeline


I’m trying to build an LXC container within the gitlab pipeline using the LXC distrobuilder. I can run the set of commands locally on my machine without an issue however when I attempt to run inside of an Ubuntu build step I receive an error stating Error: Failed to create overlay: invalid argument Which occurs just as its about to build the archive of the rootfs.

I’m not sure how to proceed from here as I am not too sure as to whats causing the issue in the first place…

I’m currently running this builder on the shared-runners on

  - build

Ubuntu Bionic x86-64:
  stage: build
  image: ubuntu:bionic
    - apt update
    - apt install -y golang-go debootstrap rsync gpg squashfs-tools git
    - go get -d -v
    - cd $HOME/go/src/
    - make
    - cd $CI_PROJECT_DIR
    - $HOME/go/bin/distrobuilder build-lxc ./ubuntu-bionic_x86-64.yaml
    - mv ./rootfs.tar.xz ./ubuntu-bionic-x86_64-unifi.tar.xz
    - mv ./meta.tar.xz ./ubuntu-bionic-x86_64-unifi.meta.tar.xz
      - ubuntu-bionic-x86_64-unifi.tar.xz
      - ubuntu-bionic-x86_64-unifi.meta.tar.xz

For things I’ve tried so far:

  • I’ve attempted to set the docker driver to use overlay2 by setting:
  DOCKER_DRIVER: overlay2
  • Various versions of the Ubuntu image from 18.04 > 19.10
  • Tried installing distrobuilder from source and from snap

a snippet of the output just as the issue occurs:

 Generating locales (this might take a while)...
   en_GB.UTF-8... done
   sv_SE.UTF-8... done
 Generation complete.
 + update-locale LANG=en_GB.UTF-8
 + mount -o bind / /mnt
 + rm -rf /mnt/run/lock /mnt/run/mount /mnt/run/systemd /mnt/run/utmp
 + umount /mnt
 + rm /etc/group- /etc/gshadow- /etc/passwd- /etc/shadow-
 Error: Failed to create overlay: invalid argument

Hi CarbonCollins,

Did you ever resolve this issue? I’m stuck at the same roadblock.
Please let me know if you found a solution.


I was unable to find a solution to this issue unfortunately :confused:

Since then I have switched to a different stack which no longer required LXC containers so I have not spent any more time on it since December 2020 on this issue.

FYI: I’ve figured it out, if anyone’s interested.

Step 1: Make a Docker container with distrobuilder inside:
(Available at: Euan Jonker / Docker Distrobuilder · GitLab)

FROM ubuntu:focal
RUN apt update && \
    DEBIAN_FRONTEND=noninteractive apt install -y lxd golang-go debootstrap rsync gpg squashfs-tools git make
RUN go get -d -v && \
    cd $HOME/go/src/ && \
RUN echo "export PATH=/root/go/bin:${PATH}" >> /root/.bashrc
CMD ["bash"]

Step 2: Use the Docker container from Step 1 to run your gitlab-ci:

  stage: build
    - cd $CI_PROJECT_DIR && /root/go/bin/distrobuilder build-lxd Lxdfile
    - mv ./rootfs.squashfs ${CI_PROJECT_NAME}-${CI_COMMIT_REF_SLUG}.squashfs
    - mv ./lxd.tar.xz ${CI_PROJECT_NAME}-${CI_COMMIT_REF_SLUG}.tar.xz
    - ls -la
      - ${CI_PROJECT_NAME}-${CI_COMMIT_REF_SLUG}.squashfs

It still says “Failed to create overlay”, but only as a warning and it does not block the progress.
It also seems to have no effect on the output artifacts.

1 Like