Google Compute Engine

Estimated reading time: 4 minutes

Create machines on Google Compute Engine. You will need a Google account and a project ID. See https://cloud.google.com/compute/docs/projects for details on projects.

Credentials

The Google driver uses Application Default Credentials to get authorization credentials for use in calling Google APIs.

So if docker-machine is used from a GCE host, authentication will happen automatically via the built-in service account. Otherwise, install gcloud and get through the oauth2 process with gcloud auth login.

Or, manually download the credentials.json file to the local, and set the GOOGLE_APPLICATION_CREDENTIALS environment variable point to its location, such as:

export GOOGLE_APPLICATION_CREDENTIALS=$HOME/gce-credentials.json

Example

To create a machine instance, specify --driver google, the project ID and the machine name.

$ gcloud auth login
$ docker-machine create --driver google --google-project PROJECT_ID vm01
$ docker-machine create --driver google \
  --google-project PROJECT_ID \
  --google-zone us-central1-a \
  --google-machine-type f1-micro \
  vm02

Options

  • --google-address: Instance’s static external IP (name or IP).
  • --google-disk-size: The disk size of instance.
  • --google-disk-type: The disk type of instance.
  • --google-machine-image: The absolute URL to a base VM image to instantiate.
  • --google-machine-type: The type of instance.
  • --google-network: Specify network in which to provision VM.
  • --google-preemptible: Instance preemptibility.
  • --google-project: required The ID of your project to use when launching the instance.
  • --google-scopes: The scopes for OAuth 2.0 to Access Google APIs. See Google Compute Engine Doc.
  • --google-subnetwork: Specify subnetwork in which to provision VM.
  • --google-tags: Instance tags (comma-separated).
  • --google-use-existing: Don’t create a new VM, use an existing one. This is useful when you’d like to provision Docker on a VM you created yourself, maybe because it uses create options not supported by this driver.
  • --google-use-internal-ip-only: When this option is used during create, the new VM will not be assigned a public IP address. This is useful only when the host running docker-machine is located inside the Google Cloud infrastructure; otherwise, docker-machine can’t reach the VM to provision the Docker daemon. The presence of this flag implies --google-use-internal-ip.
  • --google-use-internal-ip: When this option is used during create it will make docker-machine use internal rather than public NATed IPs. The flag is persistent in the sense that a machine created with it retains the IP. It’s useful for managing docker machines from another machine on the same network e.g. while deploying swarm.
  • --google-username: The username to use for the instance.
  • --google-zone: The zone to launch the instance.

The GCE driver will use the ubuntu-1604-xenial-v20161130 instance image unless otherwise specified. To obtain a list of image URLs run:

gcloud compute images list --uri

Google Compute Engine supports image families. An image family is like an image alias that always points to the latest image in the family. To create an instance from an image family, set --google-machine-image to the family’s URL.

The following command will show images and which family they belong to (if any):

gcloud compute images list

To obtain a family URL, replace <PROJECT> and <FAMILY> in the following template.

https://www.googleapis.com/compute/v1/projects/<PROJECT>/global/images/family/<FAMILY>

For example, to create an instance from the latest Ubuntu 16 LTS image, specify https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts.

Environment variables and default values

CLI optionEnvironment variableDefault
--google-addressGOOGLE_ADDRESS-
--google-disk-sizeGOOGLE_DISK_SIZE10
--google-disk-typeGOOGLE_DISK_TYPEpd-standard
--google-machine-imageGOOGLE_MACHINE_IMAGEubuntu-1510-wily-v20151114
--google-machine-typeGOOGLE_MACHINE_TYPEf1-standard-1
--google-networkGOOGLE_NETWORKdefault
--google-preemptibleGOOGLE_PREEMPTIBLE-
--google-projectGOOGLE_PROJECT-
--google-scopesGOOGLE_SCOPESdevstorage.read_only,logging.write
--google-subnetworkGOOGLE_SUBNETWORK-
--google-tagsGOOGLE_TAGS-
--google-use-existingGOOGLE_USE_EXISTING-
--google-use-internal-ipGOOGLE_USE_INTERNAL_IP-
--google-usernameGOOGLE_USERNAMEdocker-user
--google-zoneGOOGLE_ZONEus-central1-a
machine, Google Compute Engine, driver