Skip to content

Instantly share code, notes, and snippets.

@mbwhite
Last active May 5, 2023 04:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbwhite/031d11e54193d8ad37afe091a3a920a6 to your computer and use it in GitHub Desktop.
Save mbwhite/031d11e54193d8ad37afe091a3a920a6 to your computer and use it in GitHub Desktop.
WSL2 - docker buildx
# start docker - this is a helper script created to start docker as wsl2 doesn't use systemd
docker-start
ping github.com
# why a ping here? emperiically I've determined this has to occur
# otherwise for me the docker daemon messes up dns.
# don't know why, ymmv
wget https://gist.githubusercontent.com/ArturKlauser/0f0293c62f5626df0261ac994d8a46af/raw/d5863dfc22e6d65fd912c9ec760dcdc86ea320cc/check-qemu-binfmt.sh
chmod +x check-qemu-binfmt.sh
./check-qemu-binfmt.sh
# output here will indicate that
OK: docker 20.10.17 supports buildx experimental feature.
OK: kernel 5.10.102.1-microsoft-standard-WSL2 has binfmt_misc fix-binary (F) support.
OK: /proc/sys/fs/binfmt_misc is mounted
OK: update-binfmts 2.2.0 has fix-binary (F) support.
OK: QEMU installed
ERROR: QEMU not registered in binfmt_misc.
# mis this step out and odd things happen when trying to compile arm on amd64
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
./check-qemu-binfmt.sh
OK: docker 20.10.17 supports buildx experimental feature.
OK: kernel 5.10.102.1-microsoft-standard-WSL2 has binfmt_misc fix-binary (F) support.
OK: /proc/sys/fs/binfmt_misc is mounted
OK: update-binfmts 2.2.0 has fix-binary (F) support.
OK: QEMU registered in binfmt_misc with flags F (F is required).
Host looks good for docker buildx multi-architecture support.
docker buildx create --use --platform linux/amd64 --platform linux/arm64
docker buildx build --platform linux/arm64 -f Dockerfile2 .
docker buildx build --platform linux/amd64 -f Dockerfile2 .
#!/bin/bash
DOCKER_DISTRO="Ubuntu"
DOCKER_DIR=/mnt/wsl/shared-docker
DOCKER_SOCK="$DOCKER_DIR/docker.sock"
export DOCKER_HOST="unix://$DOCKER_SOCK"
if [ ! -S "$DOCKER_SOCK" ]; then
mkdir -pm o=,ug=rwx "$DOCKER_DIR"
chgrp docker "$DOCKER_DIR"
/mnt/c/Windows/System32/wsl.exe -d $DOCKER_DISTRO sh -c "nohup sudo -b dockerd < /dev/null > $DOCKER_DIR/dockerd.log 2>&1"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment