Skip to content

Instantly share code, notes, and snippets.

@umputun
Created April 29, 2021 18:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save umputun/525f57dcdbc869573a02e1d3277e0079 to your computer and use it in GitHub Desktop.
Save umputun/525f57dcdbc869573a02e1d3277e0079 to your computer and use it in GitHub Desktop.
attach to scratch-based (running) container
#!/bin/sh
docker run -d --rm --name=bbox busybox:latest sleep 10 1>/dev/null 2>/dev/null
docker cp bbox:/bin/busybox .
docker cp ./busybox "$1":/busybox
rm -f ./busybox
docker exec -u 0 -it "$1" /busybox sh -c '
export PATH="/busybin:$PATH"
/busybox mkdir /busybin 2>/dev/null
/busybox --install /busybin
sh
/busybox rm -rf /busybin /busybox
'
@umputun
Copy link
Author

umputun commented Apr 29, 2021

updated version, resolves conflict of two dk.sh on the exit:

#!/bin/sh

id="$$"
docker run -d --rm --name=bbox busybox:latest sleep 10 1>/dev/null 2>/dev/null
docker cp bbox:/bin/busybox .
docker cp ./busybox "$1":/busybox.${id}
rm -f ./busybox

docker exec -u 0 -it "$1" /busybox.${id} sh -c "
export "PATH=/busybin.${id}:'$PATH'"
/busybox.${id} mkdir /busybin.${id} 2>/dev/null
/busybox.${id} --install /busybin.${id}
sh
/busybox.${id} rm -rf /busybin.${id} /busybox.${id}
"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment