Skip to content

Docker Integration

Jessica Chioma edited this page Jul 19, 2024 · 3 revisions

Docker Integration

Project Structure

  • Docker Directory: Integrated a docker directory within the root of the Next.js application.
  • Subdirectories: Created separate subdirectories for development and production environments:
    • docker/development
    • docker/production

Docker Compose Configuration

Development Environment

  • docker/development/Dockerfile
  • docker/development/docker-compose.yml

Production Environment

  • docker/prod/Dockerfile
  • docker/prod/docker-compose.yml

Container Management

  • Each docker-compose.yml file is configured to spin up two Docker containers for the frontend application.
  • Running docker-compose up results in a total of four containers (two for development and two for production).
  • This setup ensures high availability by allowing updates to be applied to one container while the other continues to serve traffic, thus preventing downtime.
  • NGINX is configured for both load balancing and reverse proxying, ensuring efficient request routing and that no single container becomes overwhelmed.
  • A cron job is configured to automate the clearing of cache and deletion of unnecessary containers every two hours. The command that triggers the cron job is docker system prune -f. This ensures the server remains fast and does not experience lag or latency due to hoarded resources.

This comprehensive Docker setup enhances the reliability and performance of the Next.js application in both development and production environments.