|
| 1 | +# Docker Setup & Commands |
| 2 | + |
| 3 | +This application is fully containerized for both development and production. By using Docker, you eliminate "it works on my machine" issues and get a consistent environment instantly. |
| 4 | + |
| 5 | +## Architecture |
| 6 | + |
| 7 | +The `docker-compose.yml` spins up two services: |
| 8 | +1. **app:** The Node.js application container |
| 9 | +2. **mongo:** A designated MongoDB container with persistent data volumes |
| 10 | + |
| 11 | +## Prerequisites |
| 12 | + |
| 13 | +- [Docker Desktop](https://www.docker.com/products/docker-desktop/) installed and running. |
| 14 | + |
| 15 | +--- |
| 16 | + |
| 17 | +## 🔥 Quick Start (Local Orchestration) |
| 18 | + |
| 19 | +To spin up the entire application (Node.js API + MongoDB) in one command: |
| 20 | + |
| 21 | +```bash |
| 22 | +docker-compose up -d |
| 23 | +``` |
| 24 | + |
| 25 | +> **Note:** The `-d` flag runs the containers in detached mode (in the background). |
| 26 | +
|
| 27 | +### Stopping the Containers |
| 28 | +To stop the application and database gracefully: |
| 29 | +```bash |
| 30 | +docker-compose down |
| 31 | +``` |
| 32 | + |
| 33 | +--- |
| 34 | + |
| 35 | +## 🛠️ Handy Docker Commands |
| 36 | + |
| 37 | +### 1. View Application Logs |
| 38 | +If you ran `docker-compose up -d` and want to see your server logs (e.g. to see startup errors or API requests): |
| 39 | +```bash |
| 40 | +docker-compose logs -f app |
| 41 | +``` |
| 42 | + |
| 43 | +### 2. Rebuild the Application Container |
| 44 | +If you added a new NPM package or changed the `Dockerfile`, you must rebuild the image: |
| 45 | +```bash |
| 46 | +docker-compose up -d --build |
| 47 | +``` |
| 48 | + |
| 49 | +### 3. Clear Database Volumes (Reset Data) |
| 50 | +To stop the application AND permanently delete all data in the MongoDB volume (Useful for a fresh slate): |
| 51 | +```bash |
| 52 | +docker-compose down -v |
| 53 | +``` |
| 54 | + |
| 55 | +--- |
| 56 | + |
| 57 | +## 📦 Production Deployment |
| 58 | + |
| 59 | +If you are deploying to a production server (like AWS EC2, DigitalOcean, or Render), you only need to build the API image. |
| 60 | + |
| 61 | +```bash |
| 62 | +# 1. Build the production Docker image |
| 63 | +docker build -t tryappstack-api . |
| 64 | + |
| 65 | +# 2. Run the container (Make sure to pass your custom ENV file) |
| 66 | +docker run -d -p 3000:3000 --env-file config.env tryappstack-api |
| 67 | +``` |
0 commit comments