- Build this gist with
--build-arg SLEEP=1
docker buildx build https://gist.github.com/edf224977880e6e7598e76b1330f2990.git --build-arg SLEEP=1
e.g.
$ docker buildx build https://gist.github.com/edf224977880e6e7598e76b1330f2990.git --build-arg SLEEP=1
[+] Building 12.0s (5/6) docker:lima-docker
=> [internal] load git source https://gist.github.com/edf224977880e6e7598e76b1330f2990.git 2.8s
=> [internal] load metadata for docker.io/library/ubuntu:latest 0.0s
=> [builder 1/2] FROM docker.io/library/ubuntu:latest@sha256:2e863c44b718727c860746568e1d54afd13b2fa71b160f5cd9058fc436217b30 1.9s
=> => resolve docker.io/library/ubuntu:latest@sha256:2e863c44b718727c860746568e1d54afd13b2fa71b160f5cd9058fc436217b30 1.9s
=> CACHED [builder 2/2] RUN false || [ -n "1" ] # Ignore error if SLEEP is set 0.0s
=> CACHED [builder-sleep 1/2] RUN echo 'echo This shell is running in "builder-sleep" stage.' > ~/.bashrc 0.0s
=> [builder-sleep 2/2] RUN pidns=$(readlink /proc/self/ns/pid|sed -E 's/pid:\[([0-9]+)\]/\1/') && cat <<EOT && sleep 999999 7.3s
=> => # Execute the following command to attach a shell to this build stage:
=> => # - lima user:
=> => # limactl shell docker bash -c 'sudo nsenter --all --target=$(lsns|awk "/^4026532471/{print \$4}") bash'
=> => # - Docker for Mac user:
=> => # docker run -it --privileged --pid=host --rm ubuntu bash -c 'nsenter --all --target=$(lsns|awk "/^4026532471/{print \$4}") bash'
- Copy and paste the command line from the build logs to execute and attach the shell to the build stage.
Since the value passed to 'target' in the command line varies with each build, it needs to be copied from the logs.
e.g.
$ limactl shell docker bash -c 'sudo nsenter --all --target=$(lsns|awk "/^4026532471/{print \$4}") bash'
This shell is running in builder-sleep stage.
root@buildkitsandbox:/# uname -a
Linux buildkitsandbox 6.8.0-35-generic #35-Ubuntu SMP PREEMPT_DYNAMIC Tue May 21 07:52:29 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux
root@buildkitsandbox:/#