> ## Documentation Index
> Fetch the complete documentation index at: https://docs.shardcloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Migrate a Docker Compose Project to Shard Cloud

> Move a docker-compose.yml project (your services, databases, volumes, reverse proxy and workers) to Shard Cloud, step by step.

## Introduction

Shard Cloud doesn't run `docker-compose.yml` files directly: each application runs **one** container. A Compose project moves by splitting it into its parts: each service becomes a managed [application](https://docs.shardcloud.app/apps.md) or [database](https://docs.shardcloud.app/databases.md). Most of those parts get simpler on the way, since Shard Cloud manages the databases, HTTPS, restarts, backups and metrics for you, with no server to maintain.

## How Compose Maps to Shard Cloud

| In `docker-compose.yml` | On Shard Cloud |
| - | - |
| A service with `build:` (your code) | An [application](https://docs.shardcloud.app/apps.md), from your code or from a [custom Docker image](https://docs.shardcloud.app/custom-docker-images.md) |
| `image: postgres`, `mysql`, `mongo`, `redis` | A managed [database](https://docs.shardcloud.app/databases.md) |
| `image: nginx`, `traefik`, `caddy` as a reverse proxy | Usually nothing: each application gets its own address with HTTPS |
| `image: minio` or other file storage | The [Shard Cloud CDN](https://docs.shardcloud.app/cdn/introduction.md) API |
| A worker (same code, different `command:`) | Another application without a subdomain |
| `environment:`, `env_file:` | Environment variables (import a `.env` file) |
| `ports: "80:3000"` | The app listens on port 80; HTTPS is added for you |
| Service names as hostnames (`db`, `redis`, `api`) | Database connection URLs, and other apps' public addresses |
| Named volumes for your app's files | The app's persistent `/app` folder |
| Volumes of database containers | The managed database's own storage |
| `depends_on`, `healthcheck` | Not needed: apps start on their own and retry |
| `restart: always` | The default: apps restart automatically |
| `deploy.replicas` | Copies of the app behind a load balancer (Pro plan and above) |

## Before You Start

### What you need

* The project, with its `docker-compose.yml`, running somewhere you can reach (your computer or the current server), to copy the data
* A Shard Cloud account with room for every service and database (see the minimum RAM of each on the [limits page](https://docs.shardcloud.app/limits.md)). Custom Docker images need the **Core plan** or above
* [Docker](https://www.docker.com/) on your computer, to restore the databases

### Classify each service

Open `docker-compose.yml` and put each service in one of these groups:

| The service is... | It becomes... |
| - | - |
| PostgreSQL, MySQL, MongoDB or Redis | A managed database ([step 1](#step-1-create-the-databases-and-move-the-data)) |
| A self-hosted Supabase stack (`supabase/postgres`, `gotrue`, `postgrest`, `realtime`...) | One **Supabase** database ([details](https://docs.shardcloud.app/databases.md#supabase)) |
| Your code in Node.js, Python, Go, PHP, Ruby, Java, C# or Elixir | A regular application: no Dockerfile needed ([step 2](#step-2-move-your-code)) |
| Your code that needs its own Dockerfile (system packages, another language, a special build) | An application from a custom Docker image ([step 3](#step-3-services-that-need-their-own-dockerfile)) |
| A third-party web app that speaks HTTP (n8n, Metabase, Uptime Kuma...) | An application from a custom Docker image |
| A reverse proxy (nginx, Traefik, Caddy) | Usually dropped ([step 5](#step-5-replace-the-reverse-proxy)) |
| Dev-only tools (Adminer, pgAdmin, Mailhog) | Dropped: databases have a built-in [visualizer](https://docs.shardcloud.app/databases.md#database-visualizers) |
| A job queue or message broker used by your services (RabbitMQ, a Celery or Sidekiq broker) | A **Redis** database, through a Redis-based queue (BullMQ, Celery or Sidekiq with Redis) |

> [!WARNING]
>
> **Applications can't talk over a private network.** In Compose, services reach each other by name on any port (`http://api:3000`, `amqp://rabbitmq:5672`). On Shard Cloud, an application reaches another application only through its public address (`https://api.shardweb.app`), over HTTP on port 80. Databases are the exception: apps reach them through their connection URL, over Shard Cloud's private network. So a service that the others reach on a port other than HTTP (a message broker such as RabbitMQ or Kafka, an MQTT broker, a search engine reached on its own port) can't run as an application: replace it with a managed database where one fits, as in the table above.

## Step 1: Create the Databases and Move the Data

**1. Create each database**

In the [Dashboard](https://shardcloud.app/dash), create a database of the same type as each database service, with the **same version as its `image:` tag or a newer one** (`postgres:16` → PostgreSQL 17 or 18 is fine). The version can't change later. Copy each database's connection URL from its page.

**2. Dump the data from the Compose project**

Stop the services that write to the database first, so the copy is consistent. Then dump it from the running container (`db` is the service name; `-T` keeps the output binary-safe):

> [tab] PostgreSQL
>
> ```bash theme={null}
> docker compose exec -T db pg_dump -U POSTGRES_USER -Fc DATABASE_NAME > db.dump
> ```

> [tab] MySQL
>
> ```bash theme={null}
> docker compose exec -T db mysqldump -u root -p"ROOT_PASSWORD" \
>   --single-transaction --routines --triggers DATABASE_NAME > dump.sql
> ```

> [tab] MongoDB
>
> ```bash theme={null}
> docker compose exec -T mongo mongodump --archive --gzip \
>   --username USER --password PASSWORD --authenticationDatabase admin \
>   --db DATABASE_NAME > dump.archive
> ```

Use the user, password and database name from the service's `environment:` (`POSTGRES_USER`, `POSTGRES_DB`, `MYSQL_ROOT_PASSWORD`, `MONGO_INITDB_ROOT_USERNAME`...). If the project runs on a server, run this there and copy the file to your computer.

**3. Restore it into Shard Cloud**

> [tab] PostgreSQL
>
> Use the Docker image of your Shard Cloud database's major version (`postgres:17`, `postgres:18`):
>
> ```bash theme={null}
> docker run --rm -v "$PWD:/backup" postgres:17 \
>   pg_restore --verbose --no-owner --no-acl \
>   --dbname "YOUR_SHARD_CLOUD_DATABASE_URL" /backup/db.dump
> ```

> [tab] MySQL
>
> ```bash theme={null}
> mysql -h NEW_HOST -P NEW_PORT -u NEW_USER -p NEW_DATABASE < dump.sql
> ```
>
> Take the values from your Shard Cloud database's connection URL.

> [tab] MongoDB
>
> ```bash theme={null}
> mongorestore --uri "YOUR_SHARD_CLOUD_MONGODB_URL" --archive=dump.archive --gzip \
>   --nsFrom "DATABASE_NAME.*" --nsTo "database.*"
> ```
>
> `--nsFrom`/`--nsTo` renames the old database to the one in your Shard Cloud connection URL (`database` by default); leave them out if the names match.

Redis in a Compose project is usually a cache or a job queue: create a Redis database and let it start empty.

## Step 2: Move Your Code

If a service runs your own code in a [supported language](https://docs.shardcloud.app/apps.md#supported-languages), you usually don't need its Dockerfile at all: Shard Cloud's language containers install your dependencies (`package.json`, `requirements.txt`, `go.mod`...) and start the app. Translate the service into a [`.shardcloud`](https://docs.shardcloud.app/config) file:

```yaml docker-compose.yml theme={null}
services:
  api:
    build: ./api
    command: npm start
    ports:
      - "80:3000"
    environment:
      DATABASE_URL: postgres://postgres:secret@db:5432/app
    depends_on: [db]
```

becomes, in the `api` folder:

```systemd .shardcloud theme={null}
DISPLAY_NAME=My API
LANGUAGE=node
MEMORY=512
VERSION=recommended
SUBDOMAIN=myapi
CUSTOM_COMMAND=npm start
```

* **Port:** the app must listen on port 80, on `0.0.0.0`. Every language container sets `PORT=80`, so an app that reads `PORT` needs no change; one hardcoded to 3000 must be changed.
* **Build steps** from the Dockerfile (`RUN npm run build`, `RUN python manage.py collectstatic`) go in front of the start command: `CUSTOM_COMMAND=npm run build && npm start`.
* **System packages** from the Dockerfile (`apt-get install`): the language containers already include common ones (ffmpeg, Chromium's libraries, image libraries, the PostgreSQL client). If you need others, use a custom Docker image (step 3).
* **Python:** run tools as modules (`python -m gunicorn`, `python -m uvicorn main:app --host 0.0.0.0 --port 80`), since installed scripts aren't on the `PATH`.

Zip the folder **without** `node_modules/`, virtualenvs or build output, with `.shardcloud` at the root, and upload it in the [Dashboard](https://shardcloud.app/dash/applications). See your language's guide under **Languages** for details.

## Step 3: Services That Need Their Own Dockerfile

Upload the service's build context as a [custom Docker image](https://docs.shardcloud.app/custom-docker-images.md), then create an application from it. Shard Cloud builds your Dockerfile as it is, but the container runs with a few rules that a Compose setup doesn't have. Check your Dockerfile against each one:

**1. Put the Dockerfile at the root of the ZIP**

Zip the folder the service's `build: context:` points at, with the Dockerfile at the root of the ZIP and named `Dockerfile`. If Compose uses `dockerfile: docker/api.Dockerfile`, copy that file to the root as `Dockerfile`. `build: args:` don't exist here: write them as `ARG NAME=value` defaults in the Dockerfile. The ZIP can be 100 MB at most, and a build can take 15 minutes at most.

**2. Don't put your code in /app**

Every application gets a persistent folder mounted at **`/app`** (and at `/tmp`). It starts empty and hides anything the image had there, so an image that copies its code to `/app` starts with an empty folder. Use another folder for the code, and keep `/app` for the files that must survive restarts (uploads, SQLite, sessions):

```dockerfile Dockerfile theme={null}
WORKDIR /srv/app          # not /app
COPY . .
ENV DATA_DIR=/app         # persistent files go here
```

**3. Listen on port 80, and run as root**

Web traffic reaches the container on **port 80**, and `PORT` is not set for you in a custom image: set it in the Dockerfile if your app reads it (`ENV PORT=80`). The server must listen on `0.0.0.0`.

The container can only open port 80 as root, and it can't switch users after starting. Remove `USER` lines (`USER node`, `USER 1000`), and don't use entrypoints that drop privileges with `gosu` or `su-exec`. The container still runs isolated, with most root powers removed.

**4. nginx inside the image**

nginx switches its workers to another user by default, which isn't allowed. Add these two lines to `nginx.conf` (replacing its `user` line), and `listen 80`:

```nginx nginx.conf theme={null}
user root;
master_process off;
```

**5. Secrets at runtime, not at build**

Pass passwords and keys as environment variables of the application, not as build `ARG`s or files copied into the image.

> [!NOTE]
>
> An application from a custom image always runs the image's own `ENTRYPOINT`/`CMD`: there is no start command to change per application. For a worker that shares the image with the web app, either build a second image with its own `CMD`, or let one image start either role from an environment variable:
>
> ```bash entrypoint.sh theme={null}
> #!/bin/sh
> if [ "$ROLE" = "worker" ]; then
>   exec node worker.js
> fi
> exec node server.js
> ```
>
> Then set `ROLE=worker` on the worker application.

## Step 4: Rewire the Environment Variables

In Compose, services find each other by service name. Those names don't exist on Shard Cloud, so for each application, write its variables in a `.env` file and replace:

| In Compose | On Shard Cloud |
| - | - |
| `postgres://user:pass@db:5432/app` | The PostgreSQL connection URL from the database page |
| `redis://redis:6379` | The Redis connection URL |
| `mongodb://mongo:27017/app` | The MongoDB connection URL |
| `http://api:3000` | `https://myapi.shardweb.app` (the other app's public address) |
| `${VARIABLE}` from your shell or `.env` | Its actual value |

Shard Cloud databases only accept encrypted connections. Most drivers handle this with the connection URL alone; if yours connects without TLS by default, turn it on (for example `ssl: { rejectUnauthorized: false }` in Node's `pg`, or `sslmode=require`).

> [!TIP]
>
> `depends_on` doesn't exist here: every application starts on its own, maybe before the database is reachable. Make sure your app retries its first database connection instead of exiting (most frameworks and ORMs do). If it exits, it's restarted automatically anyway.

## Step 5: Replace the Reverse Proxy

In most Compose projects, nginx, Traefik or Caddy is there for HTTPS and to send each domain or path to the right service. On Shard Cloud:

* **HTTPS** is automatic for every application, on its `*.shardweb.app` address and on your own domains.
* **One domain per service** is the simplest setup: `example.com` on the frontend app, `api.example.com` on the API app. Point the frontend at the API's address, and allow it in the API's CORS settings.
* **Paths on one domain** (`/` → frontend, `/api` → API): serve the frontend from the API app (many frameworks can serve static files), or keep a small nginx application that forwards to the other apps' public addresses:

  ```nginx default.conf theme={null}
  server {
    listen 80;
    location /api/ {
      proxy_pass https://myapi.shardweb.app;
      proxy_set_header Host myapi.shardweb.app;
      proxy_ssl_server_name on;
    }
    location / {
      proxy_pass https://myfrontend.shardweb.app;
      proxy_set_header Host myfrontend.shardweb.app;
      proxy_ssl_server_name on;
    }
  }
  ```

  Build it as a custom image from `nginx` with the `user root;` and `master_process off;` lines from step 3.

WebSockets work on every application with no extra setup.

## Step 6: Deploy and Test

**1. Create each application**

Upload each service: a ZIP with `.shardcloud` for regular applications, or an application from its custom image. Give a `SUBDOMAIN` only to the services that receive web traffic (they need at least 512 MB); workers need none (256 MB).

**2. Import the environment variables**

On each application's page, open **Environment Variables**, choose **Import .env** and pick that service's file. Restart the application afterwards: variables are read when it starts.

**3. Copy persistent files**

If a service kept files in a named volume, copy them out of the old container (`docker compose cp api:/data ./data`) and upload them to the application's `/app` folder with the file manager in the dashboard.

**4. Test, then move your domain**

Test each app on its `*.shardweb.app` address, then add your domains and point their DNS at Shard Cloud. See [Custom Domain](https://docs.shardcloud.app/tutorials/platform/custom-domain.md). Keep the old project and its volumes until you've checked the data.

**5. Deploy on every push (optional)**

Connect each application to your repository on its **Deploy** page, and turn on **Auto-Restart on Deploy**. See [Git integration](https://docs.shardcloud.app/tutorials/platform/git-integration.md). A `.shardcloud` file committed to the repository applies to **every** application deployed from it: with several services in one repository, keep `.shardcloud` out of git and let each application keep its own.

## Troubleshooting

> [accordion] Custom image: Cannot find module '/app/...' (or the code folder is empty)
>
> The persistent folder mounted at `/app` hides what the image put there. Move the code to another folder (`WORKDIR /srv/app`) and rebuild. See [step 3](#step-3-services-that-need-their-own-dockerfile).

> [accordion] Custom image: permission denied when binding port 80 (EACCES)
>
> The image switches to a non-root user. Remove the `USER` line so the server runs as root.

> [accordion] nginx: setgid(101) failed (1: Operation not permitted)
>
> Add `user root;` and `master_process off;` to `nginx.conf`.

> [accordion] gosu / su-exec: operation not permitted
>
> The entrypoint tries to switch users, which isn't allowed. Start the process directly as root instead.

> [accordion] getaddrinfo ENOTFOUND db (or redis, api...)
>
> Compose service names don't exist on Shard Cloud. Use the database's connection URL, or the other application's public address (step 4).

> [accordion] The app starts but the site doesn't load
>
> The server must listen on port 80 and on `0.0.0.0`, not on another port or on `localhost` only. In a custom image, `PORT` isn't set for you: set `ENV PORT=80` if the app reads it.

> [accordion] The image build fails or times out
>
> Check the build log on the image's page. A build can take 15 minutes at most and the ZIP can be 100 MB at most: add a `.dockerignore` for `node_modules`, `.git` and build output.

> [accordion] Changed an environment variable and nothing happened
>
> Environment variables are read when the app starts: restart the application after changing them.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.