Back to Docker

Use the default Compose Bridge transformation

content/manuals/compose/bridge/usage.md

18.09-release5.5 KB
Original Source

{{< summary-bar feature_name="Compose bridge" >}}

Compose Bridge includes a built-in transformation that automatically converts your Compose configuration into a set of Kubernetes manifests.

Based on your compose.yaml file, it produces:

  • A Namespace so all your resources are isolated and don't conflict with resources from other deployments.
  • A ConfigMap with an entry for each and every config resource in your Compose application.
  • Deployments for application services. This ensures that the specified number of instances of your application are maintained in the Kubernetes cluster.
  • Services for ports exposed by your services, used for service-to-service communication.
  • Services for ports published by your services, with type LoadBalancer so that Docker Desktop will also expose the same port on the host.
  • Network policies to replicate the networking topology defined in your compose.yaml file.
  • PersistentVolumeClaims for your volumes, using hostpath storage class so that Docker Desktop manages volume creation.
  • Secrets with your secret encoded. This is designed for local use in a testing environment.

It also supplies a Kustomize overlay dedicated to Docker Desktop with:

  • Loadbalancer for services which need to expose ports on host.
  • A PersistentVolumeClaim to use the Docker Desktop storage provisioner desktop-storage-provisioner to handle volume provisioning more effectively.
  • A Kustomization.yaml file to link all the resources together.

If your Compose file defines a models section for a service, Compose Bridge automatically configures your deployment so your service can locate and use its models via Docker Model Runner.

For each declared model, the transformation injects two environment variables:

  • <MODELNAME>_URL: The endpoint for Docker Model Runner serving that model
  • <MODELNAME>_MODEL: The model’s name or identifier

You can optionally customize these variable names using endpoint_var and model_var.

The default transformation generates two different overlays - one for Docker Desktop whilst using a local instance of Docker Model Runner, and a model-runner overlay with all the relevant Kubernetes resources to deploy Docker Model Runner in a pod.

EnvironmentEndpoint
Docker Desktophttp://host.docker.internal:12434/engines/v1/
Kuberneteshttp://model-runner/engines/v1/

For more details, see Use Model Runner.

Use the default Compose Bridge transformation

To convert your Compose file using the default transformation:

console
$ docker compose bridge convert

Compose looks for a compose.yaml file inside the current directory and generates Kubernetes manifests.

Example output:

console
$ docker compose -f compose.yaml bridge convert
Kubernetes resource backend-deployment.yaml created
Kubernetes resource frontend-deployment.yaml created
Kubernetes resource backend-expose.yaml created
Kubernetes resource frontend-expose.yaml created
Kubernetes resource 0-my-project-namespace.yaml created
Kubernetes resource default-network-policy.yaml created
Kubernetes resource backend-service.yaml created
Kubernetes resource frontend-service.yaml created
Kubernetes resource kustomization.yaml created
Kubernetes resource backend-deployment.yaml created
Kubernetes resource frontend-deployment.yaml created
Kubernetes resource backend-service.yaml created
Kubernetes resource frontend-service.yaml created
Kubernetes resource kustomization.yaml created
Kubernetes resource model-runner-configmap.yaml created
Kubernetes resource model-runner-deployment.yaml created
Kubernetes resource model-runner-service.yaml created
Kubernetes resource model-runner-volume-claim.yaml created
Kubernetes resource kustomization.yaml created

All generated files are stored in the /out directory in your project.

Deploy the generated manifests

[!IMPORTANT]

Before you deploy your Compose Bridge transformations, make sure you have enabled Kubernetes in Docker Desktop.

Once the manifests are generated, deploy them to your local Kubernetes cluster:

console
$ kubectl apply -k out/overlays/desktop/

[!TIP]

You can convert and deploy your Compose project to a Kubernetes cluster from the Compose file viewer.

Make sure you are signed in to your Docker account, navigate to your container in the Containers view, and in the top-right corner select View configurations and then Convert and Deploy to Kubernetes.

Additional commands

Convert a compose.yaml file located in another directory:

console
$ docker compose -f <path-to-file>/compose.yaml bridge convert

To see all available flags, run:

console
$ docker compose bridge convert --help

What's next?