This project uses Docker Compose to orchestrate the application and the database. Below is an explanation of the volume mapping used in the docker-compose.yml:
| Service | Mapping | Type | Purpose |
|---|---|---|---|
| App | .:/usr/src/app |
Bind Mount | Synchronizes source code for hot-reloading. |
| App | /usr/src/app/node_modules |
Anonymous Volume | Hides the Mac node_modules so Linux ones can work. |
| Database | postgres_data:/var/lib/postgresql/data |
Named Volume | Persists database records across container restarts. |
This creates a two-way link between your local project folder and the container's working directory.
- Development Workflow: Any changes you make to your files (e.g.,
schema.prisma,src/index.ts) in VS Code are instantly reflected inside the container. - Efficiency: You do not need to rebuild the Docker image every time you save a file; the container simply "sees" the new code.
This is a managed volume used to store the physical PostgreSQL data files.
- Data Persistence: Containers are ephemeral. Without this volume, deleting the container would delete your entire database (including your
Booktable and migration history). - Safety: By using a Named Volume (
postgres_data), Docker stores the data in a dedicated, optimized area of your hard drive. Even if you rundocker-compose down, your data remains safe in the volume.
That specific line—/usr/src/app/node_modules—is what we call an Anonymous Volume.
When you see a volume path in a Docker Compose file that doesn't have a colon (:) or a source folder, you are essentially telling Docker: "Don't let the Mac sync anything into this specific folder."
You might be wondering: "If I'm already syncing my whole project with .:/usr/src/app, why do I need this extra line for node_modules?"
It solves a major conflict between Mac and Linux (which Docker runs on):
- The Conflict: Your Mac creates
node_modulesfor macOS. Docker needsnode_modulesfor Linux. If you sync them, your app will likely crash because the compiled binaries (like Prisma's engine) are different for Mac and Linux. - The "Hole" in the Sync: By adding
/usr/src/app/node_moduleswithout a mapping, you are telling Docker to "cut a hole" in your sync. Docker will use its own internal Linux version ofnode_modulesand ignore whatever is in thenode_modulesfolder on your MacBook.
This is an Anonymous Volume. Unlike the other mappings, it has no source directory.
- Purpose: It prevents your MacBook's
node_modulesfrom overwriting the container'snode_modules. - The Problem it Solves: Some packages (like Prisma and Bcrypt) compile differently for Mac and Linux. If you sync your Mac's
node_modulesinto the Linux container, the app will crash due to "Incompatible Binary" errors. - The Solution: This volume tells Docker to keep its own internal, Linux-compatible version of
node_modulesseparate from your local files.