- Add Dockerfile with multi-stage build for production - Add docker-compose.yml for easy deployment - Add .dockerignore to exclude unnecessary files - Add DOCKER_SETUP.md with comprehensive setup guide - Update next.config.js to enable standalone output mode - Configure app to run on port 3500 - Keep MySQL server external to Docker
3.2 KiB
3.2 KiB
Docker Setup Guide
This guide explains how to run the Ultimate Lists App using Docker on port 3500.
Prerequisites
- Docker and Docker Compose installed
- MySQL server running (external to Docker)
- Environment variables configured
Configuration
1. Update next.config.js
The application needs to be configured for standalone output. Update your next.config.js:
const nextConfig = {
output: 'standalone',
// ... rest of your config
}
2. Environment Variables
Create a .env file in the project root with your MySQL connection details:
# MySQL Connection (external server)
DATABASE_URL="mysql://user:password@host:port/database"
# For Docker host machine MySQL, use:
# DATABASE_URL="mysql://user:password@host.docker.internal:3306/database"
# NextAuth Configuration
NEXTAUTH_URL=http://localhost:3500
NEXTAUTH_SECRET=your-secret-key-here
AUTH_SECRET=your-secret-key-here
# Optional: MySQL connection check variables
DB_HOST=host.docker.internal
DB_PORT=3306
DB_USER=your-db-user
DB_PASSWORD=your-db-password
Important: If your MySQL server is running on your host machine (localhost), use host.docker.internal instead of localhost in the DATABASE_URL.
3. Run Database Migrations
Before building the Docker image, ensure your database schema is up to date:
npm install
npx prisma generate
npx prisma db push
Building and Running
Option 1: Using Docker Compose (Recommended)
# Build and start the container
docker-compose up -d
# View logs
docker-compose logs -f app
# Stop the container
docker-compose down
Option 2: Using Docker directly
# Build the image
docker build -t ultimate-lists-app .
# Run the container
docker run -d \
-p 3500:3500 \
--env-file .env \
--name ultimate-lists-app \
ultimate-lists-app
# View logs
docker logs -f ultimate-lists-app
# Stop the container
docker stop ultimate-lists-app
docker rm ultimate-lists-app
Accessing the Application
Once running, access the application at:
Troubleshooting
Cannot connect to MySQL
If you see database connection errors:
- Verify MySQL is running and accessible
- Check that you're using
host.docker.internalinstead oflocalhostin DATABASE_URL - Ensure MySQL allows connections from Docker containers
- Verify firewall settings allow the connection
Build fails
If the build fails:
- Ensure
output: 'standalone'is set innext.config.js - Check that all dependencies are properly installed
- Verify Prisma schema is valid
Port already in use
If port 3500 is already in use:
# Find what's using the port
lsof -i :3500
# Change the port in docker-compose.yml or use a different port:
docker run -p 3501:3500 ...
Development vs Production
This Docker setup is configured for production use. For development:
# Use the regular dev server
npm run dev
Updating the Application
To update after code changes:
# Rebuild and restart
docker-compose up -d --build
# Or with Docker directly
docker build -t ultimate-lists-app .
docker stop ultimate-lists-app
docker rm ultimate-lists-app
docker run -d -p 3500:3500 --env-file .env --name ultimate-lists-app ultimate-lists-app