Skip to main content

Prerequisites

Ensure you have the following installed:

Quick Start

1

Clone the Repository

git clone https://github.com/yourusername/defdrive.git
cd defdrive
2

Configure Environment Variables

Create a .env file from the example:
cp .env.example .env
Edit the .env file with your configuration. See Environment Variables for details.
3

Start Services

Launch all services using Docker Compose:
docker compose up -d
This will start:
  • DefDrive application container
  • PostgreSQL database container
4

Verify Deployment

Check that all services are running:
docker compose ps
View application logs:
docker compose logs -f app

Docker Compose Configuration

The compose.yaml file defines two services:

Application Service

app:
  build:
    context: .
    dockerfile: Dockerfile
  environment:
    - DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}
    - JWT_SECRET=${JWT_SECRET}
    - TZ=${TZ}
    - PORT=8080
    - DATA_PATH=/app/data
  ports:
    - "${PORT:-8080}:8080"
  volumes:
    - ./data:/app/data
  depends_on:
    db:
      condition: service_healthy
  restart: unless-stopped

Database Service

db:
  image: postgres:latest
  user: 999:999
  restart: unless-stopped
  environment:
    - POSTGRES_USER=${POSTGRES_USER}
    - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
    - POSTGRES_DB=${POSTGRES_DB}
    - PGDATA=/var/lib/postgresql/data/pgdata
  healthcheck:
    interval: 10s
    retries: 10
    test: pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}
    timeout: 2s
  volumes:
    - db_data:/var/lib/postgresql/data
  ports:
    - ${DB_PORT}:5432

Dockerfile

The DefDrive Dockerfile uses a multi-stage build process:
FROM golang:1.24-alpine

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download

COPY . .
RUN go build -o defdrive ./main.go

EXPOSE 8080
CMD ["./defdrive"]
The application is built inside the container, ensuring consistent builds across different environments.

Using Pre-built Images

Alternatively, you can use pre-built images from GitHub Container Registry:
app:
  image: ghcr.io/ankitprasad2005/defdrive:latest
  # ... rest of configuration
Uncomment this line in compose.yaml and comment out the build section.

Docker Compose Commands

# Start in detached mode
docker compose up -d

# Start with build
docker compose up -d --build

Data Persistence

Database Data

PostgreSQL data is persisted in a named Docker volume:
volumes:
  db_data:
This ensures your database survives container restarts.

Uploaded Files

Uploaded files are stored in a bind mount:
volumes:
  - ./data:/app/data
Files are stored on the host machine in the ./data directory, making them easily accessible and backed up.
Ensure the ./data directory has proper permissions. If running into permission issues, check the directory permissions on your host system.

Health Checks

The database service includes a health check to ensure it’s ready before the application starts:
healthcheck:
  interval: 10s
  retries: 10
  test: pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}
  timeout: 2s
The application service depends on the database health check:
depends_on:
  db:
    condition: service_healthy

Port Configuration

By default, DefDrive runs on port 8080 inside the container. You can map it to a different host port:
ports:
  - "5050:8080"  # Access via http://localhost:5050
Or set the PORT variable in your .env file:
PORT=5050

Production Deployment

Using Docker Compose in Production

1

Set Production Environment Variables

Update your .env file with production values:
  • Strong JWT_SECRET
  • Secure database credentials
  • Production HOST_URL
2

Run in Detached Mode

docker compose up -d
3

Set Up Reverse Proxy

Configure nginx or another reverse proxy to handle SSL/TLS and forward requests to DefDrive.
4

Enable Automatic Restarts

The restart: unless-stopped policy ensures containers restart automatically after system reboots.

Troubleshooting

Container Won’t Start

Check logs for errors:
docker compose logs app

Database Connection Failed

Ensure the database service is healthy:
docker compose ps
If the database is unhealthy, check database logs:
docker compose logs db

Permission Denied Errors

If you encounter permission errors with mounted volumes:
sudo chown -R 1000:1000 ./data

Port Already in Use

Change the host port mapping in compose.yaml or your .env file:
PORT=3000

Updating DefDrive

To update to the latest version:
git pull origin main
docker compose down
docker compose build --no-cache
docker compose up -d
Always backup your database before updating to prevent data loss.

Backup and Restore

Backup Database

docker compose exec db pg_dump -U ${POSTGRES_USER} ${POSTGRES_DB} > backup.sql

Restore Database

docker compose exec -T db psql -U ${POSTGRES_USER} ${POSTGRES_DB} < backup.sql

Backup Uploaded Files

tar -czf data-backup.tar.gz ./data

Next Steps

  • Configure Environment Variables for your deployment
  • Set up SSL/TLS with a reverse proxy
  • Configure automated backups
  • Monitor application logs and performance

Build docs developers (and LLMs) love