Docker SDK for Python | Docker python3
APythonlibraryfortheDockerEngineAPI.Itletsyoudoanythingthedockercommanddoes,butfromwithinPythonapps–runcontainers,managecontainers,manageSwarms,etc.FormoreinformationabouttheEngineAPI,seeitsdocumentation[1].InstallationThelateststableversionisavailableonPyPI[2].Eitheradddockertoyourrequirements.txtfileorinstallwithpip:GettingstartedTotalktoaDockerdaemon,youfirstneedtoinstantiateaclient.Youcanusefrom_env()[3]toconnectusingthedefaultsocketortheconfigurationinyourenvironment:importdockerclient=...
A Python library for the Docker Engine API. It lets you do anything the docker command does, but from within Python apps – run containers, manage containers, manage Swarms, etc.
For more information about the Engine API, see its documentation[1].
InstallationThe latest stable version is available on PyPI[2]. Either add docker to your requirements.txt file or install with pip:
Getting startedTo talk to a Docker daemon, you first need to instantiate a client. You can use from_env()[3] to connect using the default socket or the configuration in your environment:
import docker client = docker.from_env()You can now run containers:
>>> client.containers.run("ubuntu", "echo hello world") hello worldYou can run containers in the background:
>>> client.containers.run("bfirsh/reticulate-splines", detach=True) <Container 45e6d2de7c54>You can manage containers:
>>> client.containers.lis...