Skip to content

How to deploy my docker app on GCP

To deploy your Docker application on Google Cloud Platform (GCP), you can follow these general steps:

  1. Create a Google Cloud project: If you haven’t done so already, create a project on the GCP Console (console.cloud.google.com) and enable the necessary APIs and services, such as the Compute Engine and Container Registry.
  2. Build and push your Docker image: Build your Docker image locally using the Dockerfile in your application’s directory. Once the image is built, you need to push it to a container registry on GCP. The Container Registry allows you to store and manage your container images. You can use the following command to push your image:
   docker push gcr.io/your-project-id/your-image-name

Replace your-project-id with your GCP project ID and your-image-name with the desired name for your image.

  1. Create a Compute Engine instance: In GCP, you can use a Compute Engine instance as a virtual machine to run your Docker containers. Create a Compute Engine instance with the desired configuration, including the desired machine type, disk size, and networking settings. Ensure that Docker is installed on the instance.
  2. SSH into the Compute Engine instance: Once the instance is created, SSH into the instance using the SSH button provided on the Compute Engine instance details page. This will open a terminal window where you can execute commands on the instance.
  3. Pull and run your Docker image: On the Compute Engine instance, pull your Docker image from the Container Registry using the following command:
   docker pull gcr.io/your-project-id/your-image-name

After pulling the image, you can run it as a container:

   docker run -d -p 80:80 gcr.io/your-project-id/your-image-name

This command runs the container in the background (-d flag) and maps port 80 of the host machine to port 80 of the container (-p 80:80 flag).

  1. Configure firewall rules: By default, incoming traffic to the Compute Engine instance is blocked. If your application needs to be accessible from the internet, you must configure firewall rules to allow incoming traffic to the desired ports (e.g., port 80). In the GCP Console, navigate to the “VPC network” section and create a firewall rule allowing traffic on the desired port.
  2. Access your application: Once the container is running and the firewall rules are configured, you should be able to access your application by navigating to the external IP address of your Compute Engine instance in a web browser.

These steps outline deploying a Docker application on GCP using Compute Engine. YMMV.

Leave a Reply

Your email address will not be published. Required fields are marked *