如何在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.
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 amanifest.ymlfor easier management. - For certificates: Store them securely using user-provided services instead of hardcoding. Create a service instance with your certs:
You can bind this service to any app that needs the certs later.cf create-user-provided-service app-cert-service -p '{"cert": "-----BEGIN CERTIFICATE-----...", "key": "-----BEGIN PRIVATE KEY-----..."}'
- First, extract all environment variables and certificates from your
Optional: Convert docker-compose to CF manifests
Use thecf-composetool to auto-generate CF manifests from your compose file. Install it via pip:pip install cf-composeThen run:
cf-compose generateThis 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.
- For Docker-based services, push directly using your local or registry-hosted image:
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.yamlor similar) and update it to define routes that point to your deployed CF app URLs. You can get your app routes by runningcf appsafter pushing your services. - Set any required environment variables for the Microgateway, like
MGW_CONFIG_FILEto specify your config path, or credentials if your services require auth.
- Locate the configuration file (usually
Push the Microgateway to CF
- If the Microgateway uses a Dockerfile, build the local image first:
Then push it to CF Dev:docker build -t microgateway .cf push microgateway --docker-image microgateway --docker-username dummy - If it's a Node.js/Python/other language app, use a standard
cf pushwith a manifest (adjust memory/resource limits as needed):cf push microgateway -m 256M --start-command "npm start"
- If the Microgateway uses a Dockerfile, build the local image first:
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.
- Map a route to the Microgateway so traffic can reach it. For CF Dev, this is usually a local domain like
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 restageif you need to refresh service bindings.
内容的提问来源于stack exchange,提问作者rishu

