# Docker Compose

A Compose file keeps the whole setup in one place. Save one of these as `compose.yaml` in a folder of its own, then:

```
docker compose up -d          # start (and create the volume the first time)
docker compose logs -f        # the log
docker compose pull && docker compose up -d    # a newer image
docker compose down           # stop and remove the container; the volume stays
```

## A server with its own password

```yaml
services:
  crushmft27:
    image: crushftp/crushmft27:latest     # pin a tag in production, e.g. 27.0.0_289
    container_name: crushmft27
    restart: unless-stopped
    stop_grace_period: 120s               # time to finish transfers and jobs on a stop
    ports:
      - "8080:8080"                       # HTTP
      - "443:443"                         # HTTPS
      - "2222:2222"                       # SFTP
      - "21:21"                           # FTP (passive ports below)
      - "30000-30019:30000-30019"         # FTP passive range, set the same range in IP / Servers
    volumes:
      - crushmft27:/app/CrushMFT27
    environment:
      TZ: Europe/Berlin
      CRUSHFTP_ADMIN_PASSWORD_FILE: /run/secrets/crushftp_admin
    secrets:
      - crushftp_admin
    mem_limit: 2g                         # the server's heap is half of this
    read_only: true
    tmpfs:
      - /tmp
    healthcheck:
      test: ["CMD", "java", "-jar", "/app/container/CrushContainer.jar", "-health"]
      interval: 30s
      timeout: 15s
      start_period: 180s
      retries: 3

volumes:
  crushmft27: {}

secrets:
  crushftp_admin:
    file: ./admin-password.txt            # the first admin's password, used once
```

Put the password in `admin-password.txt` next to it (only the password), readable by the container's user: `chmod 644 admin-password.txt` (Compose mounts the file as it is, and the server runs as uid 65532). A file the server can't read stops the start with `CrushContainer: Error: CRUSHFTP_ADMIN_PASSWORD_FILE names /run/secrets/crushftp_admin, which the server's user (uid 65532) can not read`. After the first start you may delete the file; the password is in CrushMFT then. Change it there.

The health check runs a small Java program in the container every 30 seconds; it reports healthy once the server answers its readiness check ([Health, logs and monitoring](Health-Logs-Monitoring.md#health-checks)). `docker compose ps` shows the state.

## With a licence and settings as files

```yaml
services:
  crushmft27:
    image: crushftp/crushmft27:latest
    restart: unless-stopped
    ports:
      - "8080:8080"
      - "2222:2222"
    volumes:
      - crushmft27:/app/CrushMFT27
      - ./split_prefs:/app/CrushMFT27/split_prefs:ro
    environment:
      CRUSHFTP_ADMIN_PASSWORD_FILE: /run/secrets/crushftp_admin
    secrets:
      - crushftp_admin

volumes:
  crushmft27: {}

secrets:
  crushftp_admin:
    file: ./admin-password.txt
```

with a folder `split_prefs/` next to it, for example:

| File | Content |
|---|---|
| `_registration_name.txt` | your licence name, URL-encoded (`Example%20Corp`) |
| `_registration_email.txt` | your licence e-mail |
| `_registration_code.txt` | your licence code |
| `_log_debug_level.txt` | `0` |

[Configuration](Configuration.md#settings-as-files-split_prefs) explains these files and lists more.

## With a host folder and a files volume

```yaml
services:
  crushmft27:
    image: crushftp/crushmft27:latest
    restart: unless-stopped
    ports:
      - "443:443"
      - "2222:2222"
    volumes:
      - /srv/crushmft27:/app/CrushMFT27     # the server's data; chown 65532:0 on Linux
      - /srv/files:/files                    # the users' files; point their virtual folders at /files/...
```

Both folders must be writable by uid 65532 on Linux: `sudo chown -R 65532:0 /srv/crushmft27 /srv/files`.

## Behind a reverse proxy

With Traefik, nginx or Caddy in front, publish only the TCP protocols directly and let the proxy carry HTTP:

```yaml
services:
  crushmft27:
    image: crushftp/crushmft27:latest
    restart: unless-stopped
    expose:
      - "8080"                     # the proxy reaches it on the Compose network
    ports:
      - "2222:2222"                # SFTP goes straight in
    volumes:
      - crushmft27:/app/CrushMFT27
volumes:
  crushmft27: {}
```

Point the proxy at `http://crushmft27:8080`, and turn on the trusted proxy headers in the HTTP port's settings ([Ports and networking](Ports-and-Networking.md#https-and-certificates)). WebSockets must be passed through (CrushMFT's web interface uses them for uploads and downloads).

## The -dev image

For a shell in the container, use `crushftp/crushmft27:latest-dev` instead; nothing else changes. `docker compose exec crushmft27 bash` then works.

## FIPS 140-3 mode

Use the `-fips` tag (`crushftp/crushmft27:latest-fips`, or pinned `27.0.0_289-fips`) and nothing else changes in the file. The first start of each new version prepares the volume for FIPS mode; keep a copy of `secret.key` from the volume apart from it ([Images and tags](Images.md#fips-140-3-mode), and the CrushMFT 27 page [FIPS 140-3 mode](../CrushMFT27/FIPS-Mode.md)).
