A database stores dynamic data that an application updates. In a video-streaming service, it can hold each video’s path instead of leaving that path hardcoded in the service. The video file itself belongs in file storage; the database holds its metadata. section 4.0 section 4.5
To add MongoDB to a containerized development application:
- Add a db service to Docker Compose using the public mongo image. Other containers reach MongoDB on port 27017; a host port mapping allows access from the host. section 4.5.2
- Set DBHOST and DBNAME for the video-streaming service. In Node.js, connect with the mongodb driver, select the database, and use its videos collection. section 4.5.2
- Load a video metadata record, then run the application with docker compose up --build. section 4.5.2
A video metadata record
The sample record has an _id and a videoPath of SampleVideo_1280x720_1mb.mp4. Storing the path in MongoDB removes the need to hardcode it in the video-streaming service. section 4.5.2 section 4.5
Listing 4.5 Adding a MongoDB database
version: '3'
services:
db: #1
image: mongo:7.0.0 #2
container_name: db #3
ports:
- "4000:27017" #4
restart: always #5
azure-storage:
image: azure-storage
build:
context: ./azure-storage
dockerfile: Dockerfile
container_name: video-storage
ports:
- "4001:80"
environment:
- PORT=80
- STORAGE_ACCOUNT_NAME=${STORAGE_ACCOUNT_NAME}
- STORAGE_ACCESS_KEY=${STORAGE_ACCESS_KEY}
restart: "no"
video-streaming:
image: video-streaming
build:
context: ./video-streaming
dockerfile: Dockerfile
container_name: video-streaming
ports:
- "4002:3000"
environment:
- PORT=80
- DBHOST=mongodb://db:27017 #6
- DBNAME=video-streaming #7
- VIDEO_STORAGE_HOST=video-storage
- VIDEO_STORAGE_PORT=80
restart: "no"
The Compose listing shows the database container beside the application services, including its image, port mapping, and connection setting. section 4.5.2
A single database server can host multiple databases. Giving each microservice its own database preserves that separation as the application grows; a service that does not need a database need not connect to one. Docker Compose manages these containers for development, not production. This setup demonstrates integration rather than database design or data engineering. section 4.5.2 section 4.5.5 section 4.1 section 4.5























