Skip to content

Instantly share code, notes, and snippets.

@pasknel
Last active June 20, 2019 02:53
Show Gist options
  • Save pasknel/dba6d816df3b984411563b2ff76204a9 to your computer and use it in GitHub Desktop.
Save pasknel/dba6d816df3b984411563b2ff76204a9 to your computer and use it in GitHub Desktop.
Execute a command on all running containers
import docker
client = docker.from_env()
cmd = "ls"
for container in client.containers.list():
try:
container_name = container.name
result = container.exec_run(cmd)
print "[*] Container: {0} - Output: \n{1}".format(container_name, result.output)
except:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment