All Collections Apps Deploying with Docker Compose

Deploying with Docker Compose

Learn how to use Hatchbox to deploy an app with Docker Compose

Updated

Docker Compose can be useful for deploying custom app configurations to your servers with Hatchbox.

Installing Docker

You'll first need to install Docker on your server as root. Then follow the post-install steps for Docker.

$ curl -fsSL https://get.docker.com | sh

Add the deploy user to the Docker group:

$ sudo usermod -aG docker deploy

Port Binding

Your web container needs to bind the Hatchbox app's assigned local port so HTTP requests can be forwarded from Caddy to your container.

    ports:
- "127.0.0.1:${PORT}:80"

Project Name

Compose also needs a name for your project so it knows which project to start and stop. You can specify this either in compose.yaml or using an environment variable

compose.yml

name: my-app

ENV Variable

COMPOSE_PROJECT_NAME=my-app

Build Script

Your application will need a custom build script. This will run on all application servers:

docker compose down || true
docker compose up -d

Note: Docker Compose won't distribute containers across servers with roles in your Cluster. Each application server will run a copy of all the containers.

Example

We've put together a simple example to run Wordpress + MariaDB using Docker Compose on a Hatchbox server.

https://github.com/hatchboxio/docker-compose-example