Container

Note

Container API is available in Libcloud 1.0.0-pre1 and higher.

Note

Container API is currently in an EXPERIMENTAL state.

Container API allows users to install and deploy containers onto container based virtualization platforms. This is designed to target both on-premise installations of software like Docker as well as interfacing with Cloud Service Providers that offer Container-as-a-Service APIs.

For a working example of the container driver with cluster support, see the example for Amazon’s Elastic Container Service:

  1. from libcloud.container.base import ContainerImage
  2. from libcloud.container.types import Provider
  3. from libcloud.container.providers import get_driver
  4. cls = get_driver(Provider.ECS)
  5. conn = cls(access_id='SDHFISJDIFJSIDFJ',
  6. secret='THIS_IS)+_MY_SECRET_KEY+I6TVkv68o4H',
  7. region='ap-southeast-2')
  8. for cluster in conn.list_clusters():
  9. print(cluster.name)
  10. if cluster.name == 'default':
  11. container = conn.deploy_container(
  12. cluster=cluster,
  13. name='my-simple-app',
  14. image=ContainerImage(
  15. id=None,
  16. name='simple-app',
  17. path='simple-app',
  18. version=None,
  19. driver=conn
  20. )
  21. )

For an example of the simple container support, see the Docker example:

  1. from libcloud.container.types import Provider
  2. from libcloud.container.providers import get_driver
  3. cls = get_driver(Provider.DOCKER)
  4. driver = cls(host='https://198.61.239.128', port=4243,
  5. key_file='key.pem', cert_file='cert.pem')
  6. image = driver.install_image('tomcat:8.0')
  7. container = driver.deploy_container('tomcat', image)

Drivers

Container-as-a-Service providers will implement the ContainerDriver class to provide functionality for :

  • Listing deployed containers
  • Starting, stopping and restarting containers (where supported)
  • Destroying containers
  • Creating/deploying containers
  • Listing container images
  • Installing container images (pulling an image from a local copy or remote repository)

Driver base API documentation is found here:

Simple Container Support

  • ContainerImage - Represents an image that can be deployed, like an application or an operating system
  • Container - Represents a deployed container image running on a container host

Cluster Suppport

Cluster support extends on the basic driver functions, but where drivers implement the class-level attribute supports_clusters as True clusters may be listed, created and destroyed. When containers are deployed, the target cluster can be specified.

Bootstrapping Docker with Compute Drivers

The compute and container drivers can be combined using the deployment feature of the compute driver to bootstrap an installation of a container virtualization provider like Docker. Then using the Container driver, you can connect to that API and install images and deploy containers.

Supported Providers

For a list of supported providers see supported providers page.

Examples

We have examples of several common patterns.

API Reference

For a full reference of all the classes and methods exposed by the Container API, see this page.

Utility Classes

There are some utility classes for example, a Docker Hub API client for fetching images and iterating through repositories see this page.