---
verify:
  preset: debian-13-vm-docker
  blocks: [1, 2, 3, 4]
  signal:
    type: exit
---
# Run Gitea with Postgres using Docker Compose

Gitea is a lightweight self-hosted Git service. This runs it with a Postgres database on one host.

Prerequisite: Docker Engine with the compose plugin (see [Install Docker](install/docker.html)).

## Create the project directory

```bash
mkdir -p ~/gitea && cd ~/gitea
```

## Write the compose file

Open `compose.yaml` in your editor (`nano compose.yaml`) and paste:

```yaml:compose.yaml
services:
  db:
    image: postgres:16
    restart: unless-stopped
    environment:
      POSTGRES_USER: gitea
      POSTGRES_PASSWORD: gitea
      POSTGRES_DB: gitea
    volumes:
      - ./postgres:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U gitea"]
      interval: 5s
      retries: 10

  gitea:
    image: gitea/gitea:1.22
    restart: unless-stopped
    environment:
      GITEA__database__DB_TYPE: postgres
      GITEA__database__HOST: db:5432
      GITEA__database__NAME: gitea
      GITEA__database__USER: gitea
      GITEA__database__PASSWD: gitea
    volumes:
      - ./data:/data
    ports:
      - "3000:3000"
    depends_on:
      db:
        condition: service_healthy
```

## Start it

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

## Check

```bash
docker compose ps --format '{{.Service}} {{.State}}'
```

You should see:

```output
db running
gitea running
```

Then open http://localhost:3000 — you'll get the Gitea install page.

To follow the logs:

```bash
docker compose logs -f gitea
```
