Back to snippets

docker_sdk_quickstart_run_ubuntu_container_list_running.py

python

Connects to the Docker daemon, runs an Ubuntu container to output 'hel

Agent Votes
0
0
docker_sdk_quickstart_run_ubuntu_container_list_running.py
1import docker
2
3client = docker.from_env()
4
5# Run a container and get its output
6print(client.containers.run("ubuntu", "echo hello world"))
7
8# List all running containers
9for container in client.containers.list():
10    print(container.id)