Migrating from Docker Compose to Garden
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:
Docker Desktop 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 example Docker Compose application 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
project.garden.yml
fileIn the root of the directory, we've added project.garden.yml
with the following contents:
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
backend/backend.garden.yml
fileFor our backend
application, we've added another Garden configuration file:
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
frontend/frontend.garden.yml
fileFor the frontend
application we create separate Garden configuration file:
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
mongo/mongo.garden.yml
fileHere 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:
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
You can also try out live code synchronization with Garden.
Just run:
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
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 GitHub issues or reach out on our Discord community.
Last updated