How to Run Docker Containers on Google Cloud Platform

0
220

Google Cloud Platform has many tools for working with and running containerized apps using Docker, including managed Kubernetes and serverless container execution. We’ll discuss how to get a container service running on GCP.

Which Service Should You Use?

You basically have two options for running containers. The first is Cloud Run, which is very simple and easy to use, and will get the job done for most people. Containers are treated as “services,” which are allotted a specific amount of memory and a CPU core (or two) to use. You can make custom domains to the containers, and run apps off of different ports.

If you just want to run a simple deployment without using compute engine instances like a NGINX web server, Cloud Run will work well for you. If you’ve used AWS ECS, Cloud Run is a good replacement. However, if you need a more complex deployment, or need to implement specific autoscaling and orchestration rules, you might want to look into Kubernetes Engine, which runs a managed K8 cluster.

Google also runs a container registry service called Google Container Registry, which you can use to push updates to images and repositories, for use in Cloud Run and Kubernetes Engine.

If you don’t need all the fancy features an orchestration engine like Kubernetes offers, and just want to run some containers, Cloud Run will handle it just fine, and is what we’re focusing on here. If you want to learn more about running a fleet of containers on Kubernetes Engine, read Google’s guides on setting it up.

Getting Started with Cloud Run

Head over to the Google Cloud Platform Console, and select “Create Service.”

Select the region that you want it to run in, and give it a name.

You can also choose to secure this container with Cloud IAM. This is mostly useful if you’re deploying internal services and want to secure them so that only authorized users or service accounts can access them. If you choose this, you’ll need to give an IAM permission to the given user accounts for them to access this service.

On the next step, you’ll configure the first revision of the container service, using a URL for an image. This can be from the Docker registry, or you can use Google Container Registry.

Under “Advanced Settings,” you can configure which port to send to the container, as well as any specific entry point commands and arguments you need.

Under “Capacity,” you can change the concurrent request limit, request timeout, number of CPU cores, and memory allocated to each instance. This should optimally be just enough to run one instance of your app—if you need more capacity, autoscaling will scale it up.

Autoscaling will happen automatically, but you can lower the number of maximum instances if you’re worried about cost.

Once you click “Create,” the service will start. You’ll be able to view its details from the Cloud Run console. The URL for connecting to the container is viewable from this panel. Of course, you can use a custom domain to map to a container, but using this with a CNAME will work as well.

If you head to this URL, you’ll see your container service up and running.