Docker Container Driver Documentation

Docker containers wrap up a piece of software in a complete filesystem that contains everything it needs to run: code, runtime, system tools, system libraries – anything you can install on a server. This guarantees that it will always run the same, regardless of the environment it is running in.

../../_images/docker.png

Instantiating the driver

from libcloud.container.types import Provider
from libcloud.container.providers import get_driver

cls = get_driver(Provider.DOCKER)

conn = cls(host="https://198.61.239.128", port=4243, key_file="key.pem", cert_file="cert.pem")

conn.list_images()

API Docs

class libcloud.container.drivers.docker.DockerContainerDriver(key='', secret='', secure=False, host='localhost', port=4243, key_file=None, cert_file=None)[source]

Docker container driver class.

>>> from libcloud.container.providers import get_driver
>>> driver = get_driver('docker')
>>> conn = driver(host='198.61.239.128', port=4243)
>>> conn.list_containers()
or connecting to http basic auth protected https host:
>>> conn = driver('user', 'pass', host='https://198.61.239.128', port=443)

connect with tls authentication, by providing a hostname, port, a private key file (.pem) and certificate (.pem) file >>> conn = driver(host=’https://198.61.239.128’, >>> port=4243, key_file=’key.pem’, cert_file=’cert.pem’)

Parameters:
  • key (str) – API key or username to used (required)

  • secret (str) – Secret password to be used (required)

  • secure (bool) – Whether to use HTTPS or HTTP. Note: Some providers only support HTTPS, and it is on by default.

  • host (str) – Override hostname used for connections.

  • port (int) – Override port used for connections.

  • key_file (str) – Path to private key for TLS connection (optional)

  • cert_file (str) – Path to public key for TLS connection (optional)

Returns:

None

connectionCls

alias of DockerConnection

create_cluster(name: str, location: ClusterLocation | None = None) ContainerCluster

Create a container cluster

Parameters:
  • name (str) – The name of the cluster

  • location (ClusterLocation) – The location to create the cluster in

Return type:

ContainerCluster

deploy_container(name, image, parameters=None, start=True, command=None, hostname=None, user='', stdin_open=True, tty=True, mem_limit=0, ports=None, environment=None, dns=None, volumes=None, volumes_from=None, network_disabled=False, entrypoint=None, cpu_shares=None, working_dir='', domainname=None, memswap_limit=0, port_bindings=None, network_mode='bridge', labels=None)[source]

Deploy an installed container image

For details on the additional parameters see : http://bit.ly/1PjMVKV

Parameters:
  • name (str) – The name of the new container

  • image (libcloud.container.base.ContainerImage) – The container image to deploy

  • parameters (str) – Container Image parameters

  • start (bool) – Start the container on deployment

Return type:

Container

destroy_cluster(cluster: ContainerCluster) bool

Delete a cluster

Returns:

True if the destroy was successful, otherwise False.

Return type:

bool

destroy_container(container)[source]

Remove a container

Parameters:

container (libcloud.container.base.Container) – The container to be destroyed

Returns:

True if the destroy was successful, False otherwise.

Return type:

bool

ex_delete_image(image)[source]

Remove image from the filesystem

Parameters:

image (libcloud.container.base.ContainerImage) – The image to remove

Return type:

bool

ex_get_logs(container, stream=False)[source]

Get container logs

If stream == True, logs will be yielded as a stream From Api Version 1.11 and above we need a GET request to get the logs Logs are in different format of those of Version 1.10 and below

Parameters:
Return type:

bool

ex_list_processes(container)[source]

List processes running inside a container

Parameters:

container (libcloud.container.base.Container) – The container to list processes for.

Return type:

str

ex_rename_container(container, name)[source]

Rename a container

Parameters:
Return type:

libcloud.container.base.Container

ex_search_images(term)[source]

Search for an image on Docker.io. Returns a list of ContainerImage objects

>>> images = conn.ex_search_images(term='mistio')
>>> images
[<ContainerImage: id=rolikeusch/docker-mistio...>,
 <ContainerImage: id=mist/mistio, name=mist/mistio,
     driver=Docker  ...>]
param term:

The search term

type term:

str

rtype:

list of libcloud.container.base.ContainerImage

get_cluster(id: str) ContainerCluster

Get a cluster by ID

Parameters:

id (str) – The ID of the cluster to get

Return type:

ContainerCluster

get_container(id)[source]

Get a container by ID

Parameters:

id (str) – The ID of the container to get

Return type:

libcloud.container.base.Container

install_image(path)[source]

Install a container image from a remote path.

Parameters:

path (str) – Path to the container image

Return type:

libcloud.container.base.ContainerImage

list_clusters(location: ClusterLocation | None = None) List[ContainerCluster]

Get a list of potential locations to deploy clusters into

Parameters:

location (ClusterLocation) – The location to search in

Return type:

list of ContainerCluster

list_containers(image=None, all=True)[source]

List the deployed container images

Parameters:
Return type:

list of libcloud.container.base.Container

list_images()[source]

List the installed container images

Return type:

list of libcloud.container.base.ContainerImage

list_locations() List[ClusterLocation]

Get a list of potential locations to deploy clusters into

Return type:

list of ClusterLocation

restart_container(container)[source]

Restart a container

Parameters:

container (libcloud.container.base.Container) – The container to be stopped

Returns:

The container refreshed with current data

Return type:

libcloud.container.base.Container

start_container(container)[source]

Start a container

Parameters:

container (libcloud.container.base.Container) – The container to be started

Returns:

The container refreshed with current data

Return type:

libcloud.container.base.Container

stop_container(container)[source]

Stop a container

Parameters:

container (libcloud.container.base.Container) – The container to be stopped

Returns:

The container refreshed with current data

Return type:

libcloud.container.base.Container

supports_clusters = False

Whether the driver supports containers being deployed into clusters