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

I’ve been trying for literally days to build multiplatform Docker images with buildx in my (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 (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 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:

  stage: push-image
    - build
    DOCKER_TLS_CERTDIR: "/certs"
  image: docker:stable
    - docker:stable-dind
    - docker info
    - 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
    - echo $DOCKER_TAG
    - time docker buildx create --use
    - time docker buildx build --platform linux/amd64,linux/arm64 -t $DOCKER_TAG --push .
  • 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