Docker

Working with private repositories

If you want to run containers from private Docker repos, you will have to be signed in to that repo. Authentication sessions are stored in a file called ~/.dockercfg and are created by docker login.

headintheclouds can take care of most of this for you. If you create a file called dot_dockercfg that’s a copy of your ~/.dockercfg, the fab docker.setup command will upload this file to the remote host as ~/.dockercfg.

Tasks

headintheclouds.docker.ssh

SSH into a running container, using the host as a jump host. This requires the container to have a running sshd process.

Args:
  • container: Container name or ID
  • cmd=’‘: Command to run in the container
  • user=’root’: SSH username
  • password=’root’: SSH password
headintheclouds.docker.ps

Print a table of all running containers on a host

headintheclouds.docker.bind

Bind one or more ports to the container.

Args:
  • container: Container name or ID
  • *ports: List of items in the format CONTAINER_PORT[:EXPOSED_PORT][/PROTOCOL]
Example:
fab docker.bind:mycontainer,80,”3306:3307”,”12345/udp”
headintheclouds.docker.unbind

Unbind one or more ports from the container.

Args:
  • container: Container name or ID
  • *port: List of items in the format CONTAINER_PORT[:EXPOSED_PORT][/PROTOCOL]
Example:
fab docker.unbind:mycontainer,80,”3306:3307”,”12345/udp”
headintheclouds.docker.setup

Prepare a vanilla server by installing docker, curl, and sshpass. If a file called dot_dockercfg exists in the current working directory, it is uploaded as ~/.dockercfg.

Args:
  • version=None: Docker version. If undefined, will install 0.7.6. You can also specify this in env.docker_version
headintheclouds.docker.run

Run a docker container.

Args:
  • image: Docker image to run, e.g. orchardup/redis, quay.io/hello/world
  • name=None: Container name
  • command=None: Command to execute
  • environment: Comma separated environment variables in the format NAME=VALUE
  • ports=None: Comma separated port specs in the format CONTAINER_PORT[:EXPOSED_PORT][/PROTOCOL]
  • volumes=None: Comma separated volumes in the format HOST_DIR:CONTAINER_DIR
Examples:
  • fab docker.run:orchardup/redis,name=redis,ports=6379
  • fab docker.run:quay.io/hello/world,name=hello,ports=”80:8080,1000/udp”,volumes=”/docker/hello/log:/var/log”
  • fab docker.run:andreasjansson/redis,environment=”MAX_MEMORY=4G,FOO=bar”,ports=6379
headintheclouds.docker.kill

Kill a container

Args:
  • container: Container name or ID
  • rm=True: Remove the container or not
headintheclouds.docker.pull

Pull down an image from a repository (without running it)

Args:
image: Docker image
headintheclouds.docker.inspect

Inspect a container. Same as running docker inspect CONTAINER on the host.

Args:
container: Container name or ID
headintheclouds.docker.tunnel

Set up an SSH tunnel into the container, using the host as a gateway host.

Args:
  • container: Container name or ID
  • local_port: Local port
  • remote_port=None: Port on the Docker container (defaults to local_port)
  • gateway_port=None: Port on the gateway host (defaults to remote_port)