/gce-docker

Google Cloud Engine integration for Docker

Primary LanguageGoMIT LicenseMIT

Google Cloud Engine integration for Docker Build Status

gce-docker is a service that provides integration with the GCE to Docker, the following resources are supported:

  • Persistent Disks, the service is able to attach, format and mount persistent-disks allowing to use it as volumes in the container
  • Load Balancers & External IPs: support from auto-creation of LoadBanacers and External IPs allowing direcct access to the container.

Examples

Creating a Persistent Disk and mount is a volume to a Container

docker run -ti -v my-disk:/data --volume-driver=gce busybox df -h /data

Creating a simple Load Balancer with a static IP

docker run -d --label gce.lb.address=104.197.200.230 --label gce.lb.type=static -p 80:80tutum/hello-world

Installing

The recommended way to install gce-docker is use the provided docker image.

Run the driver using the following command:

docker run -d -v /:/rootfs -v /run/docker/plugins:/run/docker/plugins -v /var/run/docker.sock:/var/run/docker.sock --privileged mcuadros/gce-docker

privileged is required since gce-docker needs low level access to the host mount namespace, the driver mounts, umounts and format disk.

The instance requires Read/Write privileges to Google Compute Engine and IP forwarding flags should be active to.

Usage

Persistent Disks

Persistent disk creation

Using docker volume create a new disk is created.

docker volume create --driver=gce --name my-disk -o SizeGb=90

Options:

  • Type (optional, default:pd-ssd, options: pd-ssd or pd-standard): Disk type to use to create the disk.
  • SizeGb (optional): Size of the persistent disk, specified in GB.
  • SourceSnapshot (optional): The source snapshot used to create this disk.
  • SourceImaget (optional): The source image used to create this disk.

Using a disk on your container

Just add the flags --volume-driver=gce and the -v <disk-name>:/data to any docker run command:

docker run -ti -v my-disk:/data --volume-driver=gce busybox sh

If the disk already exists will be used, if not a new one with the default values will be created (Standard/500GB)

The disk is attached to the instance, if the disk is not formatted also is formatted with ext4, when the container stops, the disk is unmounted and detached.

Load Balancer

The load balancers, are handle by a watcher, waiting for Docker events, the watched events are start and die. When a new containeris created or destroyed, the LoadBalancer and all the others dependant resources are created or deleted too.

This is a small example create a LoadBalancer for a web server:

docker run -d --label gce.lb.type=ephemeral -p 80:80 tutum/hello-world

Available labels:

  • gce.lb.type (options: ephemeral or static): Type of IP to be used in the new load balancer
  • gce.lb.group (optional): Name of group of instances to assign to the same load balancer. If not provided a combination of instance name and container id will be used.
  • gce.lb.address (optional, required with type static): Value of the reserved IP address that the forwarding rule is serving on behalf of. The IP address or the IP name.
  • gce.lb.source.ranges (optional): The IP address blocks that this load balancer applies to expressed in CIDR format. One or both of sourceRanges and sourceTags may be set.
  • gce.lb.source.tags (optional):A list of instance tags which this rule applies to. One or both of sourceRanges and sourceTags may be set.
  • gce.lb.session.affinity (optional): Sesssion affinity option, must be one of the following values:
    • NONE: Connections from the same client IP may go to any instance in the pool.
    • CLIENT_IP: Connections from the same client IP will go to the same instance in the pool while that instance remains healthy.
    • CLIENT_IP_PROTO: Connections from the same client IP with the same IP protocol will go to the same instance in the pool while that instance remains healthy.

License

MIT, see LICENSE