LogoLogo
Bonsai (0.13) DocsGitHubDiscord CommunityGarden Enterprise
Bonsai (0.13)
Bonsai (0.13)
  • Welcome to Garden!
  • 🌸Overview
    • How Garden Works
    • Core Concepts
    • Adopting Garden
    • Garden vs Other Tools
  • 🌳Use Cases
    • Isolated On-Demand Preview Environments
    • Fast, Portable CI Pipelines that Run Anywhere
    • Shift Testing Left
    • Local Development With Remote Clusters
    • Jumpstart your Internal Developer Platform
  • 🌻Getting Started
    • Quickstart Guide
    • Installing Garden
    • Next Steps
  • 💐Tutorials
    • Your First Project
      • 1. Create a Garden Project
      • 2. Pick a Kubernetes Plugin
      • 3. Add Actions
      • 4. Add Tests
      • 5. Code Syncing (Hot Reload)
      • 6. Next Steps
  • 🌿Using Garden
    • About
    • Configuration Overview
    • Projects
    • Dashboard
    • Actions
    • Tests
    • Runs
    • Workflows
    • Variables and templating
    • Config Templates
    • Using the CLI
    • Modules
  • Kubernetes Plugins
    • About
    • Remote K8s Plugin Configuration
      • 1. Create a Cluster
        • AWS
        • GCP
        • Azure
      • 2. Configure Container Registry
        • AWS
        • GCP
        • Azure
        • Docker Hub
      • 3. Set Up Ingress, TLS and DNS
      • 4. Configure the Provider
    • Local K8s Plugin Configuration
      • 1. Install Local Kubernetes
      • 2. Configure the Provider
    • Ephemeral K8s Plugin Configuration
      • 1. Configure the Provider
      • 2. Login to the Garden dashboard
      • 3. Configure Ingress (optional)
      • 4. Retrieve Kubeconfig (optional)
    • Actions
      • Build
        • Container
      • Deploy
        • Kubernetes
        • Helm
        • Container
        • PersistentVolumeClaim
        • ConfigMap
      • Run and Test
        • Kubernetes Pod
        • Helm Pod
        • Kubernetes Exec
        • Container
    • Guides
      • In-Cluster Building
      • Minimal RBAC Configuration for Development Clusters
      • Deploying to Production
      • Using a Registry Mirror
  • ☘️Terraform Plugin
    • About
    • Plugin Configuration
    • Actions
  • 🌹Pulumi Plugin
    • About
    • Plugin Configuration
    • Actions
  • 🌼Other Plugins
    • Container
    • Exec (local scripts)
  • 🌷Guides
    • Migrating to Bonsai
    • Migrating from Docker Compose to Garden
    • Deprecations and updating to Cedar
    • Code Synchronization
    • Connecting a local application to a Kubernetes cluster (Local Mode)
    • Environments and namespaces
    • Using Garden in CircleCI
  • 🪷Advanced
    • Using Remote Sources
    • Custom Commands
  • 🎋Reference
    • Providers
      • conftest-container
      • conftest-kubernetes
      • conftest
      • container
      • ephemeral-kubernetes
      • exec
      • hadolint
      • jib
      • kubernetes
      • local-kubernetes
      • octant
      • otel-collector
      • pulumi
      • terraform
    • Action Types
      • Build
        • container Build
        • exec Build
        • jib-container Build
      • Deploy
        • configmap Deploy
        • container Deploy
        • exec Deploy
        • helm Deploy
        • kubernetes Deploy
        • persistentvolumeclaim Deploy
        • pulumi Deploy
        • terraform Deploy
      • Run
        • container Run
        • exec Run
        • helm-pod Run
        • kubernetes-exec Run
        • kubernetes-pod Run
      • Test
        • conftest-helm Test
        • conftest Test
        • container Test
        • exec Test
        • hadolint Test
        • helm-pod Test
        • kubernetes-exec Test
        • kubernetes-pod Test
    • Template Strings
      • Project template context
      • Environment template context
      • Provider template context
      • Action (all fields) template context
      • Action spec template context
      • Module template context
      • Remote Source template context
      • Project Output template context
      • Custom Command template context
      • Workflow template context
      • Template Helper Functions
    • Commands
    • Project Configuration
    • ConfigTemplate Reference
    • RenderTemplate Reference
    • Workflow Configuration
    • Garden Containers on Docker Hub
    • Module Template Configuration
    • Module Types
      • configmap
      • conftest
      • container
      • exec
      • hadolint
      • helm
      • jib-container
      • kubernetes
      • persistentvolumeclaim
      • pulumi
      • templated
      • terraform
  • 🌸Misc
    • FAQ
    • Troubleshooting
    • Telemetry
    • New Garden Cloud Version
  • Contributing to Garden
    • Contributor Covenant Code of Conduct
    • Contributing to the Docs
    • Setting up your developer environment
    • Developing Garden
    • Config resolution
    • Graph execution
Powered by GitBook
On this page
  • Pre-requisites
  • Getting the example application
  • The project.garden.yml file
  • The backend/backend.garden.yml file
  • The frontend/frontend.garden.yml file
  • The mongo/mongo.garden.yml file
  • Deploying the Garden project to Kubernetes
  • Running the Garden project in code synchronization mode
  • Larger migrations

Was this helpful?

  1. Guides

Migrating from Docker Compose to Garden

PreviousMigrating to BonsaiNextDeprecations and updating to Cedar

Last updated 2 months ago

Was this helpful?

If you already have an application configured to use Docker Compose and want to migrate it to Garden, you can do so by adding the necessary Garden config files. In this guide, we'll walk through an example of converting a simple Docker Compose project to Garden. You can follow along with the example, or substitute with your own Docker Compose project where relevant.

Pre-requisites

To follow along, you should have:

  • Basic familiarity with Garden (, , ).

  • running locally.

  • A local Kubernetes cluster running inside Docker Desktop.

  • A project that currently uses Docker Compose (or follow along using the provided example).

Getting the example application

Clone our and take a look around. In summary, our application is built with a backend (Express), a frontend (React), and a database (MongoDB).

The frontend and backend applications each have their own Dockerfile, and there is a top-level docker-compose.yml file to tie them together and to add MongoDB.

This application is based on the one at https://github.com/docker/awesome-compose/tree/master/react-express-mongodb. We've added four *.garden.yml files, which we'll walk through in detail.

The project.garden.yml file

In the root of the directory, we've added project.garden.yml with the following contents:

apiVersion: garden.io/v1
kind: Project
name: compose2garden

environments:
  - name: default
    variables:
      base-hostname: compose2garden.local.demo.garden

providers:
  - name: local-kubernetes

This is a Project level file. We call it compose2garden in our example, but you can use your own name. We configure a single environment and specify the hostname where we can visit the running application. Finally, we configure local-kubernetes (e.g. a Kubernetes cluster running in Docker Desktop) as our provider.

The backend/backend.garden.yml file

For our backend application, we've added another Garden configuration file:

kind: Build
apiVersion: garden.io/v1
name: backend
description: The backend server image
type: container

---
kind: Deploy
apiVersion: garden.io/v1
name: backend
description: The backend server container
type: container
dependencies:
  - build.backend
  - deploy.mongo
spec:
  image: ${actions.build.backend.outputs.deploymentImageId}
  sync:
    paths:
      - source: ./
        target: /usr/src/app
        mode: "one-way-replica"
  ports:
    - name: http
      containerPort: 3000
  healthCheck:
    httpGet:
      path: /api
      port: http
  ingresses:
    - path: /
      port: http
      hostname: backend.${var.base-hostname}

A Build action and a Deploy action are defined. Make note of the Deploy action and it's configuration.

Under sync we set up syncing from the action root to the app folder on the container, so we can synchronize code changes live when in sync mode.

Under ports we specify the same port as in our Docker Compose file (3000).

We set up a health check for the /api route, and an ingress on a subdomain. In our case, this will let us access our backend application on compose2garden.local.demo.garden.

Finally, we specify the dependency on the mongo Deploy action, which we will define in a bit.

The frontend/frontend.garden.yml file

For the frontend application we create separate Garden configuration file:

kind: Build
apiVersion: garden.io/v1
name: frontend
description: The frontend server and UI components image
type: container
exclude:
  - node_modules/**/*

---
kind: Deploy
apiVersion: garden.io/v1
name: frontend
description: The frontend server and UI components container
type: container
dependencies:
  - build.frontend
  - deploy.backend
spec:
  image: ${actions.build.frontend.outputs.deploymentImageId}
  env:
    DANGEROUSLY_DISABLE_HOST_CHECK: true
  sync:
    paths:
      - source: ./src
        target: /usr/src/app/src
        mode: "one-way-replica"
  ports:
    - name: http
      containerPort: 3000
  healthCheck:
    httpGet:
      path: /
      port: http
  ingresses:
    - path: /
      port: http

This is similar to the backend application, but we specify the backend deployment as a dependency, which makes the database (mongo) an indirect dependency.

The mongo/mongo.garden.yml file

Here we've created a mongo folder, as it did not exist in our original Docker Compose project. The folder contains only the Garden configuration file:

kind: Deploy
apiVersion: garden.io/v1
description: MongoDB for storing todo items
type: container
name: mongo

spec:
  image: mongo:4.2.0
  volumes:
    - name: data
      containerPath: /data/db
  ports:
    - name: db
      containerPort: 27017

This specifies the same volume and port that we previously specified in Docker Compose.

Deploying the Garden project to Kubernetes

To build and deploy your project run garden deploy. Once this has completed, you'll have the example "To Do" application running on your local Kubernetes cluster.

Use frontend application's ingress URL from the console output to open the application.

Running the Garden project in code synchronization mode

Just run:

garden deploy --sync

in the project folder. Garden will start up locally. You will see output in your terminal showing that this worked successfully.

Now try to modify some files in backend or frontend applications. The code changes will be synced to the running applications.

Larger migrations

You can also try out with Garden.

This is a basic example but it should give you what you need to migrate larger projects too. If you have feedback on how we could make migrating from Docker Compose easier, please send it our way via or reach out on .

🌷
Projects
Actions
Sync mode
Docker Desktop
example Docker Compose application
live code synchronization
GitHub issues
our Discord community
To Do