Last active
June 20, 2019 02:53
-
-
Save pasknel/dba6d816df3b984411563b2ff76204a9 to your computer and use it in GitHub Desktop.
Execute a command on all running containers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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