Skip to content

Instantly share code, notes, and snippets.

@pythoninthegrass
Created October 23, 2024 22:09
Show Gist options
  • Save pythoninthegrass/ab2a3fbc253951aa460a8d1c7f7e5c1a to your computer and use it in GitHub Desktop.
Save pythoninthegrass/ab2a3fbc253951aa460a8d1c7f7e5c1a to your computer and use it in GitHub Desktop.
Use the python docker sdk to run a container in detached mode
#!/usr/bin/env python
import docker
client = docker.from_env()
container = client.containers.run("ubuntu:latest",
command=["echo", "hello", "world!"],
detach=True,
remove=False,
stdout=True,
stderr=True
)
def main():
result = container.wait()
logs = container.logs()
print(logs.decode('utf-8'))
container.remove()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment