You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Cloud Foundry开发版中使用docker-compose.yml部署Docker应用及微网关

Hey there! Let's walk through getting your docker-compose app (with environment variables and certificates) deployed to Cloud Foundry Dev, plus setting up the Microgateway alongside it. I'll break this into two straightforward sections so you can follow along easily.

1. Deploying Your Docker Compose App to Cloud Foundry Dev

Cloud Foundry doesn't natively parse docker-compose.yml files directly, so we'll either deploy each service individually or use a helper tool to translate your compose config into CF-compatible manifests. Here's how:

  • Prepare your services for CF deployment

    • First, extract all environment variables and certificates from your docker-compose.yml. For env vars, you can either set them per app after pushing or define them in a manifest.yml for easier management.
    • For certificates: Store them securely using user-provided services instead of hardcoding. Create a service instance with your certs:
      cf create-user-provided-service app-cert-service -p '{"cert": "-----BEGIN CERTIFICATE-----...", "key": "-----BEGIN PRIVATE KEY-----..."}'
      
      You can bind this service to any app that needs the certs later.
  • Optional: Convert docker-compose to CF manifests
    Use the cf-compose tool to auto-generate CF manifests from your compose file. Install it via pip:

    pip install cf-compose
    

    Then run:

    cf-compose generate
    

    This will create individual manifest files for each service in your compose file. You can edit these manifests to add env vars or service bindings.

  • Push your services to CF Dev

    • For Docker-based services, push directly using your local or registry-hosted image:
      # For a local image (no registry needed for CF Dev)
      cf push my-service --docker-image my-local-image --docker-username dummy
      
    • After pushing, bind your certificate service to the app (if needed):
      cf bind-service my-service app-cert-service
      cf restage my-service
      
    • Repeat this for every service in your docker-compose setup.
2. Deploying the Microgateway to Cloud Foundry Dev

Next, let's get the Microgateway up and running to route traffic to your apps:

  • Grab the Microgateway source code
    Clone the Microgateway repository locally and navigate into its directory.

  • Configure the Microgateway

    • Locate the configuration file (usually config.yaml or similar) and update it to define routes that point to your deployed CF app URLs. You can get your app routes by running cf apps after pushing your services.
    • Set any required environment variables for the Microgateway, like MGW_CONFIG_FILE to specify your config path, or credentials if your services require auth.
  • Push the Microgateway to CF

    • If the Microgateway uses a Dockerfile, build the local image first:
      docker build -t microgateway .
      
      Then push it to CF Dev:
      cf push microgateway --docker-image microgateway --docker-username dummy
      
    • If it's a Node.js/Python/other language app, use a standard cf push with a manifest (adjust memory/resource limits as needed):
      cf push microgateway -m 256M --start-command "npm start"
      
  • Set up routing

    • Map a route to the Microgateway so traffic can reach it. For CF Dev, this is usually a local domain like apps.local:
      cf map-route microgateway apps.local --hostname my-gateway
      
    • Test by sending requests to the Microgateway's URL (e.g., http://my-gateway.apps.local) and verify it forwards traffic to your services correctly.

Quick Notes

  • Make sure your CF CLI is logged into your CF Dev instance first: cf login -a https://api.local.pcfdev.io (adjust the API endpoint to match your CF Dev setup).
  • Always use user-provided services for sensitive data like certificates—never commit them to code or manifests.
  • If your services have dependencies, deploy them in the right order (e.g., databases before apps) and use cf restage if you need to refresh service bindings.

内容的提问来源于stack exchange,提问作者rishu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:47:21