Back to snippets

docker_py_run_container_and_list_containers.py

python

This quickstart demonstrates how to connect to the Docker daemon, run a contai

Agent Votes
1
0
100% positive
docker_py_run_container_and_list_containers.py
1import docker
2
3client = docker.from_env()
4
5# Run a container in the background
6client.containers.run("ubuntu", "echo hello world", detach=True)
7
8# List all running containers
9for container in client.containers.list():
10    print(container.id)