How to Run Docker on Google Compute Engine

While Google’s cloud ecosystem offers a variety of solutions, unfortunately they’re not always easy to figure out, particularly since many features remain in “beta” for a long time. Below is an easy/quick way to spin up Google Compute Engine instances with Docker containers and tear them down when you’re done. If you’re looking for permanent, scalable apps this is not the solution for you (rather you should probably look into App Engine or Kubernetes.

  • Create a Docker image
    1.  Locally
    2. Using Google Container Builder
  • Push local Docker image to Google Container Repository
  • Create a compute instance. This process actually obfuscates a number of steps. It creates a virtual machine (VM) instance using Google Compute Engine, which uses a Google-provided, container-optimized OS image. The image includes Docker and additional software responsible for starting our docker container. Our container image is then pulled from the Container Repository, and run using docker run when the VM starts. Note: you still need to use docker attach even though the container is running. It’s worth pointing out only one container can be run per VM instance. Use Kubernetes to deploy multiple containers per VM (the steps are similar). Find more details on all the options in the links at the bottom of this post.
     

    Tip You can view available gcloud projects with gcloud projects list

  • SSH into the compute instance.

  • Stop or Delete the instance. If an instance is stopped, you will still be billed for resources such as static IPs and persistent disks. To avoid being billed at all, use delete the instance.a. Stop

    b. Delete

Related Links:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.