Containers

Create a container

import asyncio
import aiodocker

docker = aiodocker.Docker()

config = {
     "Cmd": ["/bin/ls"],
     "Image": "alpine:latest",
     "AttachStdin": False,
     "AttachStdout": False,
     "AttachStderr": False,
     "Tty": False,
     "OpenStdin": False,
 }

async def create_container():
    container = await docker.containers.create(config=config)
    print(container)
    await docker.close()


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(create_container())
    loop.close()

Reference

DockerContainers

class aiodocker.docker.DockerContainers(docker)[source]
container(container_id, **kwargs)[source]
coroutine create(config, *, name=None)[source]
coroutine create_or_replace(name, config)[source]
exec(exec_id)[source]

Return Exec instance for already created exec object.

Return type

Exec

coroutine get(container, **kwargs)[source]
coroutine list(**kwargs)[source]
coroutine run(self, config, *, auth=None, name=None)[source]

Create and start a container.

If container.start() will raise an error the exception will contain a container_id attribute with the id of the container.

Use auth for specifying credentials for pulling absent image from a private registry.

DockerContainer

class aiodocker.docker.DockerContainer(docker, **kwargs)[source]
attach(*, stdout=False, stderr=False, stdin=False, detach_keys=None, logs=False)[source]
Return type

Stream

coroutine commit(self, *, repository=None, tag=None, message=None, author=None, changes=None, config=None, pause=True)[source]

Commit a container to an image. Similar to the docker commit command.

Return type

Dict[str, Any]

coroutine delete(**kwargs)[source]
coroutine exec(self, cmd, stdout=True, stderr=True, stdin=False, tty=False, privileged=False, user='', environment=None, workdir=None, detach_keys=None)[source]
coroutine get_archive(self, path)[source]
Return type

TarFile

property id: str
Return type

str

coroutine kill(**kwargs)[source]
log(*, stdout=False, stderr=False, follow=False, **kwargs)[source]
coroutine pause(self)[source]
Return type

None

coroutine port(private_port)[source]
coroutine put_archive(path, data)[source]
coroutine rename(newname)[source]
coroutine resize(self, *, h, w)[source]
Return type

None

coroutine restart(timeout=None)[source]
coroutine show(**kwargs)[source]
coroutine start(**kwargs)[source]
stats(*, stream=True)[source]
coroutine stop(**kwargs)[source]
coroutine unpause(self)[source]
Return type

None

coroutine wait(*, timeout=None, **kwargs)[source]
coroutine websocket(**params)[source]