Google Cloud Platform (GCP) is a platform as a service that enables developers to build, deploy, and run applications on the cloud. Docker is an open-source software container engine that automates the deployment of applications on servers. This article will show you how to use Docker containers to run your applications on GCP. First, you need to create a project in GCP using the GCP Console. You can create a new project or use an existing project. When you create your project, you will be prompted to select a region. If you are not already logged in to GCP, you will need to log in first. Once you have created your project, select the Projects tab and then click on the Create button next to the Docker section. You will be prompted to select a container engine for your project: either Docker or Kubernetes. If you are new to containers, we recommend selecting Docker for this tutorial because it is more commonly used today. You can also use Kubernetes if you want later on down the road, but for now we recommend using Docker because it is simpler and more commonly used today. After selecting your container engine, click on the Next button and fill out some basic information about your project: Name (required), Description (optional), Tags (optional), and Public DNS Address(es). Click on the Create button when finished filling out these fields. Now that your project has been created, let’s start setting up some dependencies for our application: we will need NodeJS and Git installed on our development machine before we can start working with containers! To install NodeJS and Git onto our development machine, open up a terminal window and type these two commands: NodeJS installation instructions can be found here . Git installation instructions can be found here . Once NodeJS and Git have been installed onto our development machine, we can move onto setting up our environment variables so that we can ..
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.
RELATED: How to Install Docker and Docker Compose on Linux
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.