Skip to content

Latest commit

 

History

History
113 lines (87 loc) · 2.4 KB

File metadata and controls

113 lines (87 loc) · 2.4 KB

Docker Setup Guide

Quick Start

  1. Create environment file (if not exists):

    cp .env.example .env

    Edit .env and add your MongoDB connection string.

  2. Build and run containers:

    docker-compose up --build
  3. Access the application:

Docker Commands

Build containers

docker-compose build

Start containers

docker-compose up

Start in detached mode (background)

docker-compose up -d

Stop containers

docker-compose down

View logs

docker-compose logs -f

View specific service logs

docker-compose logs -f backend
docker-compose logs -f frontend

Rebuild and restart

docker-compose up --build

Remove containers and volumes

docker-compose down -v

Architecture

  • Backend: Node.js/Express server running on port 4000
  • Frontend: React app built with Vite, served via Nginx on port 80 (mapped to 5173)
  • Network: Both services communicate via hms-network bridge network
  • Nginx Proxy: Frontend nginx proxies /api and /socket.io requests to backend

Environment Variables

Backend (.env in root)

  • MONGO_URI: MongoDB connection string
  • PORT: Backend server port (default: 4000)
  • NODE_ENV: Environment (production/development)

Frontend

  • Uses relative URLs in production (via nginx proxy)
  • Uses localhost:4000 in development mode

Troubleshooting

Port already in use

If port 4000 or 5173 is already in use, modify the ports in docker-compose.yml:

ports:
  - "4001:4000"  # Change 4000 to 4001

MongoDB connection issues

  • Verify your MONGO_URI in .env file
  • Check MongoDB Atlas IP whitelist (add 0.0.0.0/0 for Docker)
  • Ensure MongoDB credentials are correct

Frontend not connecting to backend

  • Check that both containers are running: docker-compose ps
  • Verify nginx proxy configuration in frontend/nginx.conf
  • Check browser console for CORS or connection errors

Rebuild after code changes

docker-compose up --build

Production Deployment

For production, consider:

  1. Using environment-specific .env files
  2. Setting up SSL/TLS certificates
  3. Using a reverse proxy (Traefik, Nginx)
  4. Setting resource limits in docker-compose.yml
  5. Using Docker secrets for sensitive data