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

docker buildx within docker container #305

Closed
ryan-WORK opened this issue Jun 9, 2020 · 13 comments
Closed

docker buildx within docker container #305

ryan-WORK opened this issue Jun 9, 2020 · 13 comments

Comments

@ryan-WORK
Copy link

ryan-WORK commented Jun 9, 2020

Is it possible to run get docker buildx to run within a docker container?

I am running Jenkins from within a docker container and I would like to get docker buildx to run from the docker container that is also running Jenkins to build multi-arch images.

I accomplished this outside of a docker container on a Raspberry Pi, but from within the docker container with shared volumes there is no .docker.

Do you possibly have any ideas about how I can do this from within a docker container?

@jer-k
Copy link

jer-k commented Jun 11, 2020

Not sure what base image you're using, but I'll explain what I did and hopefully that can help you. I'm using alpine linux base image and installing docker from there. That package doesn't currently have buildx available so I had to install the binary the the config to enable it.

FROM alpine
ARG USER=app_user
ENV HOME /home/$USER

RUN addgroup -S appgroup && adduser -S $USER -G appgroup

RUN apk --no-cache --update upgrade && apk add --no-cache --update docker

# Create the .docker directory under /home/app_user/.docker
RUN mkdir -p $HOME/.docker/cli-plugins
COPY buildx/buildx-v0.4.0.linux-amd64 $HOME/.docker/cli-plugins/docker-buildx
COPY buildx/config.json $HOME/.docker/
RUN chown -R $USER:appgroup $HOME/.docker
RUN chmod -R 755 $HOME/.docker

This is set up with a docker-compose and using the dind image (I can post that too if need be).

Hopefully that leads you in the right direction.

@Xplouder
Copy link

Xplouder commented Oct 1, 2020

I was wondering the same "why the oficial docker container does not have buildx?" and I couldn't find documentation for it.

Nonetheless here is my version:

# syntax=docker/dockerfile:experimental

FROM docker:19.03.13

# ensure all builds runs with Buildkit
ENV DOCKER_BUILDKIT=1
# enable full log of Buildkit builds
ENV BUILDKIT_PROGRESS=plain
# enable Buildx integration with docker
ENV DOCKER_CLI_EXPERIMENTAL=enabled

ARG BUILDX_URL=https://github.com/docker/buildx/releases/download/v0.4.2/buildx-v0.4.2.linux-amd64

RUN mkdir -p $HOME/.docker/cli-plugins && \
    wget -O $HOME/.docker/cli-plugins/docker-buildx $BUILDX_URL && \
    chmod a+x $HOME/.docker/cli-plugins/docker-buildx

@FernandoMiguel
Copy link
Contributor

that's correct Docker in Docker (DinD) does not come bundled with plugins.
you need to install it

@Xplouder
Copy link

@FernandoMiguel Neither the image with just Docker.

@viceice
Copy link

viceice commented Jun 21, 2021

Which path's do i need to mount into build container?

I've tried only my workspace and the docker socket, but it can't connect to the buildkit daemon.

@crazy-max
Copy link
Member

See docker-library/docker#243. You can use this image which contains buildx and buildkit if you want.

@oneslideicywater
Copy link

oneslideicywater commented Jul 18, 2022

run this command to use docker buildx, work for me

  • os: rocky 8.5
  • docker: v20.10.17
$ docker run --name test --rm -it  -v /var/run/docker.sock:/var/run/docker.sock \
  -v /usr/bin/docker:/usr/bin/docker -v /usr/libexec/docker:/usr/libexec/docker  \
  -v /root:/root centos:7  /bin/bash
$ docker buildx ls

@benmoss
Copy link

benmoss commented Jan 13, 2023

@oneslideicywater the reason that works is you're mounting in your docker binaries from your host. People are looking for an image where buildx is already installed

@a-a-k
Copy link

a-a-k commented Jun 14, 2023

is there any appeared here in 2023?

@viceice
Copy link

viceice commented Jun 15, 2023

is there any appeared here in 2023?

works for me as expected

@Nasller
Copy link

Nasller commented Dec 5, 2024

In WSL2
-v /mnt/wsl/docker-desktop/cli-tools/usr/local/lib/docker:/usr/local/lib/docker
add this to your docker run, /mnt/wsl/docker-desktop/cli-tools/usr/local/lib/docker this path can find in your wsl linux system, such as unbuntu20.04, cd /usr/local/lib/docker in this path then ll your can find the path
Image
then docker buildx version is success in docker container
Image

@viceice
Copy link

viceice commented Dec 5, 2024

In WSL2 -v /mnt/wsl/docker-desktop/cli-tools/usr/local/lib/docker:/usr/local/lib/docker add this to your docker run, /mnt/wsl/docker-desktop/cli-tools/usr/local/lib/docker this path can find in your wsl linux system, such as unbuntu20.04, cd /usr/local/lib/docker in this path then ll your can find the path Image then docker buildx version is success in docker container Image

I don't need this, it works by design

> docker buildx version
github.com/docker/buildx v0.18.0-desktop.2 44b68677dee147502ef0be4cbead34310e44d1f6

@Nasller
Copy link

Nasller commented Dec 5, 2024

In WSL2 -v /mnt/wsl/docker-desktop/cli-tools/usr/local/lib/docker:/usr/local/lib/docker add this to your docker run, /mnt/wsl/docker-desktop/cli-tools/usr/local/lib/docker this path can find in your wsl linux system, such as unbuntu20.04, cd /usr/local/lib/docker in this path then ll your can find the path Image then docker buildx version is success in docker container Image

I don't need this, it works by design

docker buildx version
github.com/docker/buildx v0.18.0-desktop.2 44b68677dee147502ef0be4cbead34310e44d1f6

Yes sir, this is just one case I've encountered in docker desktop and doesn't work for everyone

# 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

10 participants