byronwall/recipes-modern

Create Dockerfile and docker-compose

Closed this issue · 3 comments

Dockerfile needs to build the NextJS site

Docker compose should include the site and a postgres database

Relevant info

Ignore build errors: https://nextjs.org/docs/app/api-reference/next-config-js/typescript

module.exports = {
  typescript: {
    // !! WARN !!
    // Dangerously allow production builds to successfully complete even if
    // your project has type errors.
    // !! WARN !!
    ignoreBuildErrors: true,
  },
}

Rough start

Dockerfile for Next.js

# Base image
FROM node:14

# Create app directory
WORKDIR /app

# Install dependencies
COPY package*.json ./
RUN npm install

# Copy the rest of the app's source code
COPY . .

# Build the app, ignoring type errors
RUN npm run build -- --ignore-errors

# Expose port
EXPOSE 3000

# Start the app
CMD ["npm", "start"]

Docker Compose File

version: '3.8'

services:
  web-app:
    build: .
    ports:
      - "3000:3000"
    depends_on:
      - db
    environment:
      - DATABASE_URL=postgres://user:password@db:5432/dbname
    networks:
      - app-network

  db:
    image: postgres:13
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: password
      POSTGRES_DB: dbname
    ports:
      - "5432:5432"
    networks:
      - app-network

networks:
  app-network:
    driver: bridge

Key Points

  • Dockerfile:

    • Uses Node.js base image.
    • Sets working directory to /app.
    • Installs dependencies and copies source code.
    • Builds the Next.js app, ignoring type errors.
    • Exposes port 3000 and starts the app.
  • docker-compose.yml:

    • Defines web-app service using the Dockerfile build context.
    • Maps port 3000 to host.
    • Includes PostgreSQL database (db) service.
    • Sets up required environment variables.
    • Both services are connected through a custom network app-network.

This setup ensures the Next.js app is built and runs with a PostgreSQL database, ignoring type issues during the build process.

Process is complete. Had to fight a bit with ENV variables. Decided to call them out via .env which eventually works with Coolify