Docker

Deploy your project on your own infrastructure with Docker

Building the Docker Image

Build your application's Docker image using the following command:

Terminal
pnpm docker:build

Running the Container

Run the container with basic configuration:

Terminal
docker run -p 3000:3000 expostarter-web \
  -e BASE_URL=https://your-domain.com \
  -e POSTGRES_URL=postgres://postgres:password@host:5432/dbname

Production Deployment with Docker Compose

Below is a complete example using Docker Compose with Traefik as a reverse proxy, featuring:

  • Automatic SSL certificate management
  • PostgreSQL database
  • Secure HTTPS redirection
  • Container health checks
docker-compose.yml
services:
  traefik:
    image: traefik:v2.10
    command:
      - --providers.docker=true
      - --providers.docker.exposedbydefault=false
      - --entrypoints.web.address=:80
      - --entryPoints.websecure.address=:443
      - --entrypoints.web.http.redirections.entryPoint.to=websecure
      - --entrypoints.web.http.redirections.entryPoint.scheme=https
      - --entrypoints.web.http.redirections.entrypoint.permanent=true
      - --certificatesResolvers.le.acme.email=${LE_EMAIL}
      - --certificatesResolvers.le.acme.storage=/shared/acme.json
      - --certificatesResolvers.le.acme.httpchallenge=true
      - --certificatesResolvers.le.acme.httpChallenge.entryPoint=web
      - --certificatesresolvers.le.acme.tlschallenge=true
    ports:
      - 80:80
      - 443:443
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - /app/docker-volume/traefik:/shared
      - /etc/localtime:/etc/localtime:ro      
    labels:
      - "traefik.http.routers.traefik-rtr.tls=true"
 
  expostarter-web:
    image: ghcr.io/expo-starter/expo-starter-kit/webapp
    depends_on:
      postgres:
        condition: service_healthy
    ports:
      - 3000:3000
    environment:
      - BASE_URL=https://${DOMAIN}
      - NODE_ENV=production
      - POSTGRES_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
      - UPLOADTHING_TOKEN=${UPLOADTHING_TOKEN}
      - APPLE_AUTH_CLIENT_ID=${APPLE_AUTH_CLIENT_ID}
      - GOOGLE_SIGNIN_AUDIENCE=${GOOGLE_SIGNIN_AUDIENCE}
    labels:
      - traefik.enable=true
      - traefik.http.routers.expostarter-web.rule=Host(`${DOMAIN}`)
      - traefik.http.services.expostarter-web.loadbalancer.server.port=3000
      - "traefik.http.routers.expostarter-web.tls=true"
      - "traefik.http.routers.expostarter-web.tls.certresolver=le"
      - "traefik.http.routers.expostarter-web.entrypoints=websecure"
      - "traefik.http.middlewares.expostarter-web.redirectscheme.scheme=https"
      - "traefik.http.middlewares.expostarter-web.redirectscheme.permanent=true"
 
  postgres:
    image: postgres:15.4
    restart: always
    ports:
      - '42345:5432'
    volumes:
      - /app/docker-volume/postgres:/var/lib/postgresql/data:rw
    environment:
      - POSTGRES_DB=${POSTGRES_DB}
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
    healthcheck:
      test: ['CMD-SHELL', "sh -c 'pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}'"]
      interval: 10s
      timeout: 3s
      retries: 3

Environment Variables

Create a .env file in your project root with these required variables:

.env
# Domain configuration
DOMAIN=your-domain.com
LE_EMAIL=your-email@example.com
 
# Database configuration
POSTGRES_DB=expostarter
POSTGRES_USER=postgres
POSTGRES_PASSWORD=your-secure-password
 
# Other required environment variables
UPLOADTHING_TOKEN=your-uploadthing-token
APPLE_AUTH_CLIENT_ID=your-apple-auth-client-id
GOOGLE_SIGNIN_AUDIENCE=your-google-signin-audience

Deployment Steps

  1. Install Docker and Docker Compose on your server
  2. Copy the docker-compose.yml and .env files to your server
  3. Create required directories:
    mkdir -p /app/docker-volume/{traefik,postgres}
  4. Start the services:
    docker compose up -d

Troubleshooting

If you encounter issues:

  1. Check container logs: docker compose logs -f [service-name]
  2. Verify environment variables are set correctly
  3. Ensure all required ports are accessible
  4. Check your domain's DNS configuration points to your server

On this page