zenodotus280

Docker-on-Google

This assumes that you have a Google Cloud account set up and that you've created a project. There are plenty of tutorials on how to do this so I'm focusing on the VM generation. In this example I, slippinjimmy want to create a VM called astoria that is free, optimized for Docker, and has easy remote SSH access from my desktop.

Before starting, it is important that your private SSH key has a usable name at the end of it because of how Google handles third-party SSH tools. For example, an RSA key I created on Windows had name@PCNAME at the end. This will likely cause problems.

For example, on Linux: cd ~/.ssh && ssh-keygen -t ed25519 -C "slippinjimmy" will create two keys. The public one will end in .pub

Project Keys In the "Compute Engine" section there will be "VM Instances" at the top and "Settings/Metadata" near the bottom. Select Metadata then select the "SSH Keys" tab and add your public key.

Check Google's Free Tier closely for Always Free resources. I will note clearly when an option may not be free.

Lastly, I am not an expert. I hope everything works for you but what follows is merely breadcrumbs for myself.

Creating the Instance

Name: astoria - can be anything

Region: us-west1 - cannot be changed once chosen; check which regions are free

Zone: us-west1-b - cannot be changed once chosen; check which zones are free

Machine Configuration

Series: E2

Machine Type: e2-micro - the only option that will be free; the cost estimate will not reflect this but the credits will be applied later (equiv. to 31 days every month if I recall correctly)

Boot Disk

Operating System: Container Optimized OS - stripped down OS

Version: Default (most recent x86/64 LTS)

Boot disk type: Standard persistent disk - Very important! You will get charged money if you leave it on the default of Balanced.

Size: 30 GB - the maximum allowed on the Free Tier

Firewall

Allow both HTTP and HTTPS. SSH will automatically be added.

Advanced Options

Network Interfaces

Open the drop-down and look for "External IPv4 address". Change this to from Ephemeral to Static (will need to create if you don't already have one for the current project). There is no charge for this!

Security

There are two ways to complete this step.

  1. Project-wide SSH keys (described earlier - you can open a new browser tab to add this)

  2. Instance-specific SSH keys

Instance Keys

Select the drop-down box labeled "Manage Access" and select "Add Item". Paste your public SSH key here.

Final Touches

You will see a note at the bottom mentioning that your free trial credit will be used. Click create!

After a minute or so you should be able to access via SSH:

ssh slippinjimmy@36.120.130.140 -i ~/.ssh/slippinjimmy

There is only about 60 items in /bin and there is no package manager! While docker run hello-world works out of the box there is no docker-compose. Use the following script to create an alias that runs Docker Compose as a container:

#!/bin/bash
VERSION=${1:-1.27.4}

echo alias docker-compose="'"'docker run --rm \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v "$PWD:$PWD" \
    -w="$PWD" \
    docker/compose:'"${VERSION}"''"'" >> ~/.bashrc

echo "* Pull container image for docker-compose ..."
docker pull docker/compose:${VERSION}

echo "* Done"
source ~/.bashrc

From here, install Portainer, Traefik, and any other Docker container of your choosing. Python 3.6 was installed so it is possible to manage this VM with Ansible. See Google's Documentation for more information.

Thoughts? Leave a comment

Comments
  1. Anonymous — Nov 27, 2022:

    I didn't realize "the cost estimate will not reflect this but the credits will be applied later". Quite useful to know; I had misgivings about starting another VM due to this.

    Out of curiosity, what's special about the install script you linked to for dockers-compose? Why not install docker-compose manually, as per Docker's documentation0?

  2. zenodotus280Nov 27, 2022:

    The official documentation you're referencing simply didn't work for me. I've updated the instructions to remove any dependencies on a specific gist on Github.