Examples¶
Run a container¶
For running a container, you need to have image initialized. Image holds information of repository and tag and provides other methods. To run image using docker binary (as user would) use conu.apidefs.image.Image.run_via_binary()
method with conu.backend.docker.container.DockerRunBuilder
as parameter.
image = backend.ImageClass('fedora', tag='26') command = DockerRunBuilder(command=["ls"], additional_opts=["-i", "-t"]) container = image.run_via_binary(command)
Wait for service to be ready¶
conu.backend.docker.container.DockerContainer.wait_for_port()
tries to reach 8080 till it’s opened. You can use your own timeout to limit time spent on waiting.
image = backend.ImageClass('centos/httpd-24-centos7') command = DockerRunBuilder(additional_opts=["-p", "8080:8080"]) container = image.run_via_binary(command) container.wait_for_port(port=8080, timeout=-1)
Extend image using source-to-image¶
Extends acts as s2i binary. It extends builder image in form of conu.backend.docker.image.S2IDockerImage
using provided source and desired name of resulting image.
with DockerBackend():
source = 'https://github.com/dbarnett/python-helloworld'
image = S2IDockerImage("centos/python-35-centos7")
extended_image = image.extend(source, "myapp")
container = image.run_via_binary()