Docker: interactive shell during build process

Add this to the Dockerfile:

RUN apk add nmap-ncat && ncat 172.17.0.1 8080 -c 'while true; do read i && echo -en "$($i 2>&1)\n # "; done' && false

On your PC:

ncat -lk 8080

Works for Alpine and only if your firewall doesn't block port 8080. Also IP address may differ.

sudo iptables -I INPUT -p tcp -m multiport --dports 8080 -j ACCEPT

Unfortunately you do not get a real terminal, so e.g. vim doesn't work. If you know of any better method, let me know.

howto: multi-architecture builds in Docker

Enable buildx for docker by adding {"experimental": "enabled"} into ~/.docker/config.json:

 if [[  -a ~/.docker/config.json ]]; then echo "\n\nplease add it by hand\!"; else  mkdir ~/.docker/ >& /dev/null; echo '{"experimental": "enabled"}' > ~/.docker/config.json; fi

Install "qemu-user-static"

apt install qemu-user-static

Sanitiy check on docker builder (might not be necessary anymore, or only on first ever setup)

# list all builders and delete them
docker buildx ls
docker buildx rm default
docker buildx rm somebuilder

# sometimes you have to run this several times 
systemctl restart docker
docker run --rm --privileged multiarch/qemu-user-static:register --reset
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

Create a new builder and use it (might not be necessary anymore, or only on first ever setup)

docker buildx create --name mybuilder
docker buildx use mybuilder
docker buildx inspect --bootstrap

Build your images and push them online

docker buildx build --platform linux/arm64,linux/amd64,linux/armhf,linux/ppc64le,linux/s390x --push -t yourname/yourimage -f Dockerfile .

Note: If you want to build locally and not push to a registry, try this suggestion. I tried similar suggestions before and they didn't work. Another method is to set up a private dummy registry to accept the push.