Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
In [3]:
import docker
Get a Container¶
In [4]:
client = docker.from_env()
In [6]:
client.containers.list()
Out[6]:
Get a container by ID.
In [7]:
client.containers.get("2b5cdb0477")
Out[7]:
Get a container by name.
In [8]:
client.containers.get("nervous_germain")
Out[8]:
In [9]:
dir(client.containers.get("nervous_germain"))
Out[9]:
In [10]:
client.containers.get("nervous_germain").stop()
Pushing Docker Images¶
The stream=True
option streams the output as a blocking generator,
which is much eaiser to parse.
The option decode=True
decodes the blocking output as a dict,
which makes it easie to parse.
You can refer to dsutil.docker
for a real example of parsing the streaming output of pushing Docker images using docker-py.
In [ ]:
client = docker.from_env()
for line in client.images.push(
"dclong/jupyterhub-ds", "latest", stream=True, decode=True
):
print(line)
In [ ]: