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

# Self-Host with Docker Compose

This section outlines the necessary steps to run Dittofeed with docker compose.

Watch the following video walkthrough to see how to set up Dittofeed with docker compose.

<iframe className="w-full aspect-video" src="https://www.youtube.com/embed/kZbDvVCylVg?si=4P9uoHFttEmrZD2i" title="Setting Up Dittofeed with Docker Compose" frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen />

First, clone Dittofeed's github repository.

```bash theme={null}
git clone https://github.com/dittofeed/dittofeed.git
cd dittofeed
```

## Overriding Default Environment Variables

It's important that you override the default environment variables in the `.env` file, for security reasons.

<Info>
  Dittofeed has dependencies on Postgres, and Clickhouse, with an optional Kafka dependency.
</Info>

To start, create a local `.env` file.

```bash theme={null}
touch .env
```

Then uncomment the following lines from the `docker-compose.lite.yaml` [file](https://github.com/dittofeed/dittofeed/blob/main/docker-compose.lite.yaml):

```yaml docker-compose.lite.yaml theme={null}
# README: To add local env variables uncomment the following line and add a .env file in the root directory
env_file:
  - .env
```

Populate this `.env` file with the following values, substituting placeholder values with your own. Dittofeed will work without these overrides, but it is recommended that you substitute your own credentials.

```properties .env theme={null}
DATABASE_USER=my-postgres-user
DATABASE_PASSWORD=my-postgres-password
CLICKHOUSE_USER=my-clickhouse-user
CLICKHOUSE_PASSWORD=my-clickhouse-password
PASSWORD=password
SECRET_KEY=GEGL1RHjFVOxIO80Dp8+ODlZPOjm2IDBJB/UunHlf3c=

# You need to set the following ENV variables when you are ready to deploy to a
# non-local environment, with a different domain.

# Used to generate links to the dashboard e.g. for unsubscribe links. Should not
# include the /dashboard suffix.
# DASHBOARD_URL="https://my-dittofeed-dashboard.com"

# Used to issue requests to the api from the dashboard. Should not include the
# /api suffix. Can be the same as the DASHBOARD_URL.
# DASHBOARD_API_BASE="https://my-dittofeed-api.com"
```

See our documentation on [Authentication Modes](/deployment/self-hosted/auth-modes) for instructions on how to generate a new `SECRET_KEY`.

Finally, start Dittofeed's services.

```bash theme={null}
docker compose -f docker-compose.lite.yaml up -d
```

<Warning>
  The above command will start Postgres and Clickhouse. You
  may decide to use a third party vendor for these data stores. In that case,
  you should disable the corresponding services in the
  `docker-compose.prod.yaml` file.
</Warning>

## Fixing Port Conflicts

You may be running other services on your host machine that conflict with Dittofeed's ports. If this is the case, you can override the ports that Dittofeed binds to in the `docker-compose.lite.yaml` file

First, comment out the `ports` section in the service dependencies which don't need to be exposed.

```yaml docker-compose.lite.yaml theme={null}
  temporal:
    # ports:
    #   - "7233:7233"
  ...
  postgres:
    # ports:
    #   - "5432:5432"
  ...
  clickhouse-server:
    # ports:
    #   - "8123:8123"
```

Then, change the lite service to expose the free port you want to use.

```yaml docker-compose.lite.yaml theme={null}
  lite:
    ports:
      - "3210:3000"
```

Configure the Dittofeed dashboard to use the new port.

```yaml .env theme={null}
x-backend-app-env: &backend-app-env
  <<: [*clickhouse-credentials, *database-credentials]
  DASHBOARD_API_BASE: ${DASHBOARD_API_BASE:-http://localhost:3210}
```

Finally, restart Dittofeed.

```bash theme={null}
docker compose -f docker-compose.lite.yaml up -d --force-recreate
```
