LogoLogo
Bonsai (0.13) DocsGitHubDiscord CommunityGarden Enterprise
Docs Edge
Docs Edge
  • Welcome to Garden!
  • Overview
    • What is Garden
    • 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
    • Garden vs Other Tools
  • Getting Started
    • Quickstart
    • Garden Basics
    • 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
    • Setting up a Kubernetes cluster
      • 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
  • Using Garden With
    • Containers
      • Using Remote Container Builder
      • Building Containers
    • Kubernetes
      • Using Remote Kubernetes
      • Using Local Kubernetes
      • Deploying K8s Resources
      • Installing Helm charts
      • Running Tests and Tasks
    • Terraform
      • Using Terraform
      • Applying Terrform Stacks
    • Pulumi
      • Using Pulumi
      • Applying Pulumi Stacks
    • Local Scripts
  • Features
    • Remote Container Builder
    • Team Caching
    • Variables and Templating
    • Config Templates
    • Workflows
    • Code Synchronization
    • Custom Commands
    • Remote Sources
  • Guides
    • Connecting a Project
    • Environments and Namespaces
    • Installing Garden
    • Including/Excluding files
    • Installing Local Kubernetes
    • Migrating from Docker Compose to Garden
    • Using the CLI
    • Using Garden in CircleCI
    • Minimal RBAC Configuration for Development Clusters
    • Deploying to Production
    • Using a Registry Mirror
    • Local mode
  • Reference
    • Providers
      • container
      • ephemeral-kubernetes
      • exec
      • jib
      • kubernetes
      • local-kubernetes
      • 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
        • container Test
        • exec 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
    • Glossary
    • Module Template Configuration
    • Module Types
      • configmap
      • container
      • exec
      • helm
      • jib-container
      • kubernetes
      • persistentvolumeclaim
      • pulumi
      • templated
      • terraform
  • Misc
    • FAQ
    • Troubleshooting
    • Telemetry
    • How Organizations Adopt Garden
    • New Garden Cloud Version
    • Migrating to Bonsai
  • 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
  • Prerequisites
  • 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

PreviousInstalling Local KubernetesNextUsing the CLI

Last updated 1 month 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.

Prerequisites

To follow along, you should have:

  • Basic familiarity with and ).

  • 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 .

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