Skip to content

Instantly share code, notes, and snippets.

@henrymazza
Forked from timhodson/runCommandAllDockers.sh
Last active March 28, 2021 04:08
Show Gist options
  • Save henrymazza/359907492f482b6a77639d151bd2fd46 to your computer and use it in GitHub Desktop.
Save henrymazza/359907492f482b6a77639d151bd2fd46 to your computer and use it in GitHub Desktop.
Run a command on all docker containers
#!/bin/sh
if [ $# -eq 0 ]; then
echo "No arguments provided"
exit 1
fi
for container in `docker ps -q`; do
# show the name of the container
printf '%-40s' $(docker inspect --format='{{.Name}}' $container)
# run the command (date in the case)
docker exec -it $container $1;
done
@henrymazza
Copy link
Author

Like:

my ❯ ~/bin/docker-exec-all "arch"                               ✹ git:docker-arm-4 [2.7.2][1:01]

/my_web                          aarch64
/my_master                       x86_64
/my_spring_run_ed69199aa473      aarch64
/my_sidekiq                      aarch64
/my_redis_insight                x86_64
/my_worker                       x86_64
/my_manager                      x86_64
/my_redis                        aarch64
/web-code-sync                   x86_64

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