Nov 18, 20268 min read

How to Deploy a Docker Compose App to Google Cloud

Four ways to move a docker-compose.yml with an API, a worker, Postgres and Redis to Google Cloud: declaring the services in code with Encore, gcloud run compose up, Compose on a Compute Engine VM, and Cloud Run with Cloud SQL and Memorystore by hand.

Illustration for How to Deploy a Docker Compose App to Google Cloud

A docker-compose.yml with an API, a worker, Postgres and Redis is a common starting point, and docker compose up runs it all on a laptop. Google Cloud has no single service that runs that file the same way in production, so the move means choosing where each service lands.

This guide maps each Compose service to a GCP product and compares four routes as of November 18, 2026: declaring the services in code with Encore, gcloud run compose up, Compose on a Compute Engine VM, and Cloud Run with Cloud SQL and Memorystore wired by hand.

How Compose services map to Google Cloud

The starting point is this Compose file:

services: api: build: . command: ./server ports: ["8080:8080"] environment: DATABASE_URL: postgres://app:app@postgres:5432/shop REDIS_URL: redis://redis:6379 depends_on: [postgres, redis] worker: build: . command: ./worker environment: DATABASE_URL: postgres://app:app@postgres:5432/shop REDIS_URL: redis://redis:6379 postgres: image: postgres:17 environment: POSTGRES_USER: app POSTGRES_PASSWORD: app POSTGRES_DB: shop volumes: ["pgdata:/var/lib/postgresql/data"] redis: image: redis:7 volumes: pgdata:
Compose serviceOn Google CloudWith Encore
apiCloud Run serviceAPI endpoints, deployed to Cloud Run
workerCloud Run service with Pub/Sub push, or a worker poolPub/Sub subscription in the same code
postgresCloud SQL for PostgreSQLsqldb.NewDatabase
redis as a cacheMemorystore for Rediscache.NewCluster
redis as a queuePub/Sub topic and subscriptionpubsub.NewTopic
environment secretsSecret ManagerEncore secrets
pgdata volumeCloud SQL storage with backupsManaged by Cloud SQL

Option 1: Declare the Compose services in code with Encore

Encore

Encore is a backend framework with built-in infrastructure for Go and TypeScript. Instead of listing containers in YAML, the database, the cache and the queue are declared in the code that uses them, and deploying to your GCP project runs the service on Cloud Run with Cloud SQL, Memorystore and Pub/Sub provisioned, per the GCP infrastructure docs. Locally, encore run starts the API, the worker, Postgres and the cache together, the job docker compose up did before.

Application code passes through Encore and infrastructure guardrails to resources provisioned in your own AWS or GCP account.
Get started
brew install encoredev/tap/encore &&
encore app create
Copy

Run in your terminal to get started locally.

The orders table enforces a unique idempotency key, so two concurrent requests with the same key cannot both insert a new order:

-- shop/migrations/1_orders.up.sql CREATE TABLE orders ( id BIGSERIAL PRIMARY KEY, sku TEXT NOT NULL, qty INTEGER NOT NULL, status TEXT NOT NULL DEFAULT 'pending', idempotency_key TEXT NOT NULL UNIQUE ); CREATE TABLE order_outbox ( order_id BIGINT PRIMARY KEY REFERENCES orders (id) );
package shop import ( "context" "errors" "time" "encore.dev/cron" "encore.dev/pubsub" "encore.dev/storage/cache" "encore.dev/storage/sqldb" ) // The "postgres" service: Cloud SQL for PostgreSQL in your GCP project. var db = sqldb.NewDatabase("shop", sqldb.DatabaseConfig{Migrations: "./migrations"}) // The "redis" service: Memorystore for Redis. var cluster = cache.NewCluster("shop", cache.ClusterConfig{ EvictionPolicy: cache.AllKeysLRU, }) var stock = cache.NewIntKeyspace[string](cluster, cache.KeyspaceConfig{ KeyPattern: "stock/:key", DefaultExpiry: cache.ExpireIn(10 * time.Minute), }) type OrderPlaced struct { OrderID int64 } // Replaces the queue the "worker" container read from Redis: Pub/Sub on GCP. var placed = pubsub.NewTopic[*OrderPlaced]("order-placed", pubsub.TopicConfig{ DeliveryGuarantee: pubsub.AtLeastOnce, }) type OrderParams struct { IdempotencyKey string `json:"idempotency_key"` SKU string `json:"sku"` Qty int `json:"qty"` } type OrderResponse struct { ID int64 `json:"id"` } // The "api" container's endpoint. // //encore:api public method=POST path=/orders func PlaceOrder(ctx context.Context, p *OrderParams) (*OrderResponse, error) { if p.IdempotencyKey == "" { return nil, errors.New("idempotency_key is required") } tx, err := db.Begin(ctx) if err != nil { return nil, err } defer tx.Rollback() var id int64 err = tx.QueryRow(ctx, ` INSERT INTO orders (sku, qty, idempotency_key) VALUES ($1, $2, $3) ON CONFLICT (idempotency_key) DO NOTHING RETURNING id`, p.SKU, p.Qty, p.IdempotencyKey).Scan(&id) if errors.Is(err, sqldb.ErrNoRows) { if err := tx.QueryRow(ctx, `SELECT id FROM orders WHERE idempotency_key = $1`, p.IdempotencyKey).Scan(&id); err != nil { return nil, err } if err := tx.Commit(); err != nil { return nil, err } if _, err := placed.Publish(ctx, &OrderPlaced{OrderID: id}); err == nil { _, _ = db.Exec(ctx, `DELETE FROM order_outbox WHERE order_id = $1`, id) } return &OrderResponse{ID: id}, nil } if err != nil { return nil, err } if _, err := tx.Exec(ctx, `INSERT INTO order_outbox (order_id) VALUES ($1)`, id); err != nil { return nil, err } if err := tx.Commit(); err != nil { return nil, err } if _, err := placed.Publish(ctx, &OrderPlaced{OrderID: id}); err == nil { _, _ = db.Exec(ctx, `DELETE FROM order_outbox WHERE order_id = $1`, id) } return &OrderResponse{ID: id}, nil } var _ = cron.NewJob("flush-order-outbox", cron.JobConfig{ Title: "Publish pending placed-order events", Schedule: "* * * * *", Endpoint: FlushOrderOutbox, }) //encore:api private func FlushOrderOutbox(ctx context.Context) error { rows, err := db.Query(ctx, `SELECT order_id FROM order_outbox ORDER BY order_id LIMIT 100`) if err != nil { return err } defer rows.Close() var ids []int64 for rows.Next() { var id int64 if err := rows.Scan(&id); err != nil { return err } ids = append(ids, id) } if err := rows.Err(); err != nil { return err } for _, id := range ids { if _, err := placed.Publish(ctx, &OrderPlaced{OrderID: id}); err != nil { return err } if _, err := db.Exec(ctx, `DELETE FROM order_outbox WHERE order_id = $1`, id); err != nil { return err } } return nil } type StockResponse struct { Available int64 `json:"available"` } // Reads stock through the cache, as the old API did with Redis. // //encore:api public method=GET path=/stock/:sku func Stock(ctx context.Context, sku string) (*StockResponse, error) { n, err := stock.Get(ctx, sku) if err == nil { return &StockResponse{Available: n}, nil } if !errors.Is(err, cache.Miss) { return nil, err } // Every SKU starts with 100 units in this example. err = db.QueryRow(ctx, ` SELECT (100 - COALESCE(sum(qty), 0))::bigint FROM orders WHERE sku = $1`, sku).Scan(&n) if err != nil { return nil, err } if err := stock.Set(ctx, sku, n); err != nil { return nil, err } return &StockResponse{Available: n}, nil } // The "worker" container: a subscription that runs in the same service. var _ = pubsub.NewSubscription(placed, "fulfil", pubsub.SubscriptionConfig[*OrderPlaced]{ Handler: func(ctx context.Context, msg *OrderPlaced) error { var sku string err := db.QueryRow(ctx, ` UPDATE orders SET status = 'fulfilled' WHERE id = $1 AND status = 'pending' RETURNING sku`, msg.OrderID).Scan(&sku) if errors.Is(err, sqldb.ErrNoRows) { return nil // already fulfilled by an earlier delivery } else if err != nil { return err } _, err = stock.Delete(ctx, sku) return err }, })

The worker container becomes a subscription, and the conditional UPDATE makes a redelivered message harmless. The sample compiles with encore check and go vet against encore.dev v1.57.13, and the SQL was run against Postgres 17. The databases, caching and Pub/Sub docs cover each primitive, and connecting your own cloud covers linking the GCP project.

A coding agent that adds a service or a queue writes Go code instead of editing a Compose file and a separate Terraform module, and the next push provisions it in the project.

Best fit: Go or TypeScript Compose apps moving to GCP for production that want managed Postgres, Redis and queues with no Terraform to maintain.

Option 2: gcloud run compose up

Cloud Run's Compose deploy reads the Compose file with gcloud run compose up compose.yaml, builds images from build entries into Artifact Registry and deploys one Cloud Run service with each Compose service as a container in it. It maps secrets to Secret Manager and configs to Cloud Storage, and it sets the service to a maximum of 1 instance by default. Google's docs describe it as ideal for development and recommend Terraform for production, and Postgres in a container on Cloud Run has no durable disk, so the database still has to move to Cloud SQL.

Best fit: a quick staging or demo copy of a Compose app on GCP.

Option 3: Compose on a Compute Engine VM

Create a VM, install Docker with the Compose plugin, copy the file and run docker compose up -d. It is the smallest change, and everything shares one machine: the Compute Engine docs cover snapshots for the disk, and backups, OS patches, TLS certificates and restarts after a reboot are yours. Moving postgres to Cloud SQL first removes the riskiest part.

Best fit: internal tools and prototypes where one VM's uptime is acceptable.

Option 4: Cloud Run, Cloud SQL and Memorystore by hand

The production layout built by hand is one Cloud Run service per container, Cloud SQL for PostgreSQL connected through the Cloud SQL connector, Memorystore for Redis reached through Direct VPC egress, Pub/Sub for the worker, Secret Manager for credentials and a service account per service with the right IAM roles. Written in Terraform it is a few hundred lines, and every new container or queue adds to it.

Best fit: teams with a platform engineer and an existing Terraform setup for GCP.

Which route to choose

Pick Encore when the Compose app is going to production on GCP and you want Cloud SQL, Memorystore and Pub/Sub to come from the code. Pick gcloud run compose up for a quick staging copy, a Compute Engine VM for an internal tool, and the hand-built layout when a platform team already owns Terraform for the project.

Frequently asked questions

Can I deploy a docker-compose.yml directly to Google Cloud?

Yes. The `gcloud run compose up` command deploys the Compose file as one Cloud Run service with multiple containers. Google's docs position it for development: it supports a subset of Compose fields, sets the service to a maximum of 1 instance by default, and recommends Terraform for production.

Is Docker Compose on a Compute Engine VM good enough for production?

Yes, for a small internal app, but everything shares one VM, so a reboot or disk failure takes down the API and the database together, and backups, OS patches, TLS and scaling are yours. Moving Postgres to Cloud SQL and Redis to Memorystore removes the riskiest part even if the containers stay on the VM.

What replaces the postgres and redis containers on Google Cloud?

Cloud SQL for PostgreSQL replaces the postgres container, with automated backups and optional high availability, and Memorystore for Redis replaces the redis container. A worker that read jobs from a Redis list usually becomes a Pub/Sub subscription, which retries failed messages and keeps a dead-letter topic.

How do I move a Compose app with Postgres, Redis and a worker to GCP with Encore?

Declare the database, a cache cluster and a Pub/Sub topic with a subscription in Go or TypeScript, then push. Encore deploys the API and the worker to Cloud Run in your GCP project and provisions Cloud SQL, Memorystore and Pub/Sub for them, while encore run keeps the one-command local setup that Compose gave you.

Deploy to your cloud on AWS and Google Cloud
without managing infrastructure

Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.

~/orders — claude
Claude Code
Claude Code v2.1.180Opus 5.5~/orders