Last active
April 7, 2016 06:22
-
-
Save tonybaloney/07e43245bcafb65ec15574e08105868d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Today I used as the blog post as a starting point https://libcloud.apache.org/blog/2016/02/05/libcloud-containers-example.html. I came across a couple of issues with the example code that meant it didn't work. I have made some small changes to your example to get it to work. I also found that the install_image(path) method sometimes gets a JSON parsing error due to the docker API streaming multiple new line limited json messages. By adding the check if the image has been downloaded allows it to be rerun again and the deployment will work. With the docker image tomcat:8.0 you need to provide a command parameter in deploy_container call otherwise the container starts and immediately stops. Will continue to evaluate as it looks like it will be very useful. | |
Code for my working example below: | |
from libcloud.container.providers | |
import get_driver from libcloud.container.types | |
import Provider | |
driver = get_driver(Provider.DOCKER) | |
docker_driver = driver(host='https://198.61.239.128', port=4243, key_file='key.pem', cert_file='cert.pem') | |
path='tomcat:8.0' | |
# Check to see if image already downloaded | |
image = None | |
images = docker_driver.list_images() | |
dl = [ dl_image for dl_image in images if dl_image.path == path] | |
if len(dl) > 0: | |
image = dl[0] | |
if image is None: | |
# Need to download & install | |
image = docker_driver.install_image(path) | |
bindings = { "22/tcp": [{ "HostPort": "11022" }], "8080/tcp": [{ "HostPort": "18080" }] } | |
container = driver.deploy_container('my_test_container', image, command='catalina.sh run', port_bindings=bindings) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment