Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

How to enable buildx when using DinD? #349

Closed
rolandjitsu opened this issue Aug 17, 2020 · 4 comments
Closed

How to enable buildx when using DinD? #349

rolandjitsu opened this issue Aug 17, 2020 · 4 comments

Comments

@rolandjitsu
Copy link

rolandjitsu commented Aug 17, 2020

I'm trying to implement a CI pipeline using Docker in Docker on Gitlab. And so far it seem to work, but I was wondering if there's a way to enable the buildx command for the child docker containers.

I can run docker buildx on the host, but the child docker containers don't seem to have this.

Do I need to manually download the buildx binary? If I do, where should it actually go as there's no home dir to move it to?

NOTE: I'm using the official docker image.

@tonistiigi
Copy link
Member

If I do, where should it actually go as there's no home dir to move it to?

wdym? if you run the docker image as root then home dir is /root

@rolandjitsu
Copy link
Author

rolandjitsu commented Aug 18, 2020

@tonistiigi I'm not sure how Gitlab runs the image. But I'm going to try to download and install buildx into root and see if that works.

Tried the following:

image: docker:19.03.13-beta2
stage: build
variables:
  DOCKER_DRIVER: overlay2
  DOCKER_TLS_CERTDIR: "/certs"
  BUILDX_VERSION: v0.4.1
services:
  - name: docker:19.03.13-beta2-dind  
    command: ["--experimental"]
before_script:
  - apk add curl
  - mkdir -p /root/.docker/cli-plugins
  - curl -sSLo /root/.docker/cli-plugins/buildx https://github.com/docker/buildx/releases/download/$BUILDX_VERSION/buildx-$BUILDX_VERSION.linux-amd64
  - chmod +x /root/.docker/cli-plugins/buildx
  - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  - docker info
script:
  - docker buildx

But the buildx CLI cmd is still not available.

Eventually, after going through the README, I replaced buildx -> docker-buildx and that seems to work.

So for others stumbling into the same issue, the following should work:

image: docker:19.03.13-beta2
stage: build
variables:
  DOCKER_DRIVER: overlay2
  DOCKER_TLS_CERTDIR: "/certs"
  BUILDX_VERSION: v0.4.1
services:
  - name: docker:19.03.13-beta2-dind  
    command: ["--experimental"]
before_script:
  - apk add curl
  - mkdir -p ~/.docker/cli-plugins
  - curl -sSLo ~/.docker/cli-plugins/docker-buildx https://github.com/docker/buildx/releases/download/$BUILDX_VERSION/buildx-$BUILDX_VERSION.linux-amd64
  - chmod +x ~/.docker/cli-plugins/docker-buildx
  - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  - docker info
script:
  - docker buildx

@maniator
Copy link

This is one of the reasons I created a fork of the official docker image with one that has buildx built in https://hub.docker.com/r/maniator/dind-buildx

@tonistiigi
Copy link
Member

Buildx is available in main docker image now

 docker run -it --rm --entrypoint=docker docker buildx --help

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants