It's 2023. How do I build multiplatform Docker images in my gitlab.com CI pipeline?

I’ve been trying for literally days to build multiplatform Docker images with buildx in my gitlab.com (SaaS, not self-hosted) CI pipelines & totally failing. I’ve searched the interwebs for answers and nothing works.

Can someone please tell me what the secret incantation should be in my .gitlab-ci.yml file for CI pipelines running on gitlab.com (SaaS, not self-hosted).

  • I’m trying to use docker buildx create --use and it’s failing with the message error: could not create a builder instance with TLS data loaded from environment. Please use docker context create to create a context for current environment and then create a builder instance withdocker buildx create `.

  • Using gitlab.com SaaS

  • Add the CI configuration from .gitlab-ci.yml and other configuration if relevant (e.g. docker-compose.yml)

Relevant job of .gitlab-ci.yml:

push-image:
  stage: push-image
  dependencies:
    - build
  variables:
    DOCKER_TLS_CERTDIR: "/certs"
  image: docker:stable
  services:
    - docker:stable-dind
  before_script:
    - docker info
  script:
    - time docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY
    - export COMMIT_TAG="$(cat VERSION)"
    - if $(echo "$CI_COMMIT_TAG" | grep -q -E "$FORCE_REGEX"); then export COMMIT_TAG="$COMMIT_TAG-$CI_COMMIT_TAG"; echo "LABEL ci-force=$CI_COMMIT_TAG" >> Dockerfile; fi
    - echo "$COMMIT_TAG"
    - export HIVEMQ_IMAGE_TAG="$(cat Dockerfile | grep -E '\s+as\s+download\s*$' | awk '{ print $2 }')"
    - echo "LABEL commit=$CI_COMMIT_SHA hivemq='$HIVEMQ_IMAGE_TAG'" >> Dockerfile
    - cat Dockerfile
    - export DOCKER_TAG_PREFIX=$CI_REGISTRY/artesion/private/edge/$CI_PROJECT_NAME
    - export DOCKER_TAG=$DOCKER_TAG_PREFIX:$COMMIT_TAG
    - echo $DOCKER_TAG
    - time docker buildx create --use
    - time docker buildx build --platform linux/amd64,linux/arm64 -t $DOCKER_TAG --push .
  rules:
    - if: '$CI_COMMIT_TAG =~ $CI_RULES_PRERELEASE_VERSION_REGEX || $CI_COMMIT_TAG =~ $CI_RULES_GA_RELEASE_VERSION_REGEX || $CI_COMMIT_TAG =~ $CI_RULES_FORCE_REGEX'
  • What troubleshooting steps have you already taken? Can you link to any docs or other resources so we know where you have been?

All over the Internet

I’m having this exact problem. Did you find any solution yet?

EDIT: I found the solution in another website, you just need to create the context and use that very same name on buildx create:

- docker context create builder
- docker buildx create builder --use
2 Likes