Dec 062015
 
Google Cloud and Docker

Using the developer console of Google Cloud, deploying a CoreOS VM, connecting to it, using docker commands to start a Docker container was easy.

Here now the console version:

# Might need this once:
ssh-agent bash
ssh-add google_compute_engine
gcloud components update
gcloud config set compute/zone asia-east1-b
# Start instance
gcloud compute instances start instance-1
# See what we got
gcloud compute instances describe instance-1
# Set DNS
gcloud dns record-sets transaction start --zone="kubota7"
gcloud dns record-sets transaction add --zone="kubota7" --name="mq.kubota7.info." --ttl=300 --type=A "104.144.197.212"
gcloud dns record-sets transaction execute --zone="kubota7"
# Add firewall ports to open (port 1883)
gcloud compute firewall-rules create "mqtt" --allow tcp:1883 --description "MQTT traffic" --network "default" --source-ranges "0.0.0.0/0"

Now the fun part! We have an DNS record of a host which can run docker images. We allowed tcp:1883. Now let’s start it:

gcloud compute ssh instance-1 --command "docker run -d -p 1883:1883 hkubota/mosquitto:1.4.5"

Done!
Now tearing it all down:

gcloud compute ssh instance-1 --command "docker stop 3f262028d7abd0b9a5efa3b6bfc69c04e378244d8878f5fdf6e81c2ec38b8631"
yes | gcloud compute firewall-rules delete "mqtt"  
gcloud dns record-sets transaction start --zone="kubota7"
gcloud dns record-sets transaction remove --zone="kubota7" --name="mq.kubota7.info." --ttl 300 --type A "104.144.197.212"
gcloud dns record-sets transaction execute --zone="kubota7"
gcloud compute instances stop instance-1