import DockerCompose from "@site/src/components/DockerCompose";
import StaticTraefikConfig from "@site/src/components/StaticTraefikConfig";
import DynamicTraefikConfig from "@site/src/components/DynamicTraefikConfig";

# Docker Compose

:::warning

This guide assumes you already have a Linux server with Docker and Docker compose installed. If you don't, please refer to the [official Docker documentation](https://docs.docker.com/get-docker/) for installation instructions. You must also have root access to the server.

:::

This guide will walk you through setting up the Docker Compose stack manually without using the installer CLI tool.

## Prerequisites

- A Linux system with root access and a public IP address
  - We recommend Ubuntu or Debian based systems
- [A domain name pointed to your server's IP address](../02-dns-networking.md)
- [TCP ports 80, 443, and UDP port 51820 exposed to your Linux instance.](../02-dns-networking.md)
- An email address for Let's Encrypt certificate registration
- (Optionally) a SMTP server

## Folder Structure

Anything marked with `(*)` will not be generated on startup of the stack. The volumes are created by the Docker Compose file, and most of the files are generated by the Pangolin and Gerbil services.

You will need to create the `traefik_config.yml` and `dynamic_config.yml` files manually and edit them to your needs.You can start the stack without the Traefik config files to let Pangolin generate everything. Traefik will throw some errors, but you can ignore this on first startup.

```
.
├── config/
│   ├── config.yml (*)
│   ├── db/
│   │   └── db.sqlite
│   ├── key
│   ├── letsencrypt/
│   │   └── acme.json
│   ├── logs/
│   └── traefik/
│       ├── traefik_config.yml (*)
│       └── dynamic_config.yml (*)
└── docker-compose.yml (*)
```

## Purpose of Each File

- `config/config.yml`: The main configuration file for Pangolin. See the [Configuration](https://docs.fossorial.io/Pangolin/Configuration/config) section for more details.
- `config/db/db.sqlite`: The SQLite database file for Pangolin. It will be created on startup.
- `config/key`: The key file containing the private key. It will be created when Gerbil starts.
- `config/letsencrypt/acme.json`: The Let's Encrypt certificate storage file. It will be created on startup and maintained by Traefik.
- `config/logs/`: The directory where logs are stored (if `save_logs` is enabled in the config).
- `config/traefik/traefik_config.yml`: The Traefik configuration file that contains the global settings.
- `config/traefik/dynamic_config.yml`: The Traefik configuration file that contains the dynamic configuration, such as the HTTP routers and services for the Pangolin frontend and backend.
- `docker-compose.yml`: The Docker Compose file that defines the services for Pangolin, Traefik, and Gerbil.

_For any Traefik configuration changes beyond what is needed in this tutorial, please refer to the [Traefik documentation](https://doc.traefik.io/traefik/)._

## Docker Compose File

 <DockerCompose />

## Traefik Configuration

`config/traefik/traefik_config.yml`

<StaticTraefikConfig />

`config/traefik/dynamic_config.yml`

The dynamic configuration file is where you define the HTTP routers and services for the Pangolin frontend and backend. Below is an example configuration for a Next.js frontend and an API backend.

The domain you enter here is what will be used to access the main Pangolin dashboard. Make sure you have the DNS set up correctly for this domain. Point it to the IP address of the server running Pangolin.

<DynamicTraefikConfig />

## Pangolin Configuration

`config/config.yml`

See the [Configuration](https://docs.fossorial.io/Pangolin/Configuration/config) section for more details and examples.

## Starting the Stack

After creating the necessary files and directories, you can start the stack with the following command:

```bash
sudo docker compose up -d
```

You can tail the logs of the services with:

```bash
sudo docker compose logs -f
```
