Skip to content

Instantly share code, notes, and snippets.

@alvery
Last active April 5, 2022 18:21
Show Gist options
  • Save alvery/c8730ef936ad2fc98bfd63f66b5fe0a8 to your computer and use it in GitHub Desktop.
Save alvery/c8730ef936ad2fc98bfd63f66b5fe0a8 to your computer and use it in GitHub Desktop.
Easily attach to any docker container with choice. Put the script below in /usr/bin/dcattach chmod +x /usr/bin/dcattach
#!/bin/bash
containers=($(sudo docker ps --format '{{.Names}}' | sort));
select container in "${containers[@]}"; do
[ -z "$container" ] || sudo docker exec -it $container /bin/sh -c \
"[ -x /bin/bash ] && /bin/bash || /bin/sh";
break; done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment