简体   繁体   English

Docker Compose 到 Cloud Run

[英]Docker Compose to Cloud Run

i created a docker compose file containing django apps and postgresql, and it runs perfectly.我创建了一个包含 django 应用程序和 postgresql 的 docker compose 文件,它运行完美。 then I'm confused whether I can deploy this docker compose file to the google container registry to run a cloud run?那么我很困惑是否可以将此 docker compose 文件部署到 google 容器注册表以运行云运行?

    version: "3.8"

services:
  app:
    build: .
    volumes:
      - .:/app
    ports:
      - 8000:8000
    image: django-app
    container_name: django_container
    command: >
      bash -c "python manage.py migrate
      && python manage.py runserver 0.0.0.0:8000"
    depends_on:
      - db

  db:
    image: postgres
    volumes:
      - ./data/db:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=nukacola
      - POSTGRES_PASSWORD=as938899
    container_name: postgres_db

thank you for answering my question谢谢你回答我的问题

You cannot run a docker-compose configuration on Cloud Run.您无法在 Cloud Run 上运行 docker-compose 配置。 Cloud Run only supports individual containers. Cloud Run 仅支持单个容器。 To run your Django app on Cloud Run, you can do the following.要在 Cloud Run 上运行您的 Django 应用,您可以执行以下操作。

  • Build your docker image for Django locally using the docker build command.使用docker build命令在本地为 Django 构建 docker 镜像。
  • Push the image to GCR using docker push command.使用docker push命令将镜像推送到 GCR。
  • Create a new Cloud Run service and use the newly pushed Docker image.创建一个新的 Cloud Run 服务并使用新推送的 Docker 映像。
  • Create a Cloud SQL Postgres instance and use its credentials as environment variables in your Cloud Run service.创建 Cloud SQL Postgres 实例并将其凭据用作 Cloud Run 服务中的环境变量。

You can also host your own Compute Engine instance and run docker-compose on it but I would not recommend that.您还可以托管自己的 Compute Engine 实例并在其上运行 docker-compose,但我不建议这样做。

You can also create a GKE cluster and run Django and Postgres in it but it requires knowledge of Kubernetes(deployments, statefulsets, services etc).您还可以创建 GKE 集群并在其中运行 Django 和 Postgres,但这需要了解 Kubernetes(部署、状态集、服务等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM