⚙️ Understanding Docker Compose
Docker Compose is a tool used to define and run multi-container Docker applications. It uses a YAML configuration file (
docker-compose.yml
🚀 Why Use Docker Compose?
- Simplifies managing multi-container applications
- Centralizes configuration for services, ports, volumes, and networks
- Eliminates the need for long and complex commands
docker run
- Enables repeatable development and testing environments
🧪 Example: Node.js with MongoDB
A basic Compose setup for a Node.js app that uses MongoDB:
version: '3.8' services: app: build: . ports: - "3000:3000" depends_on: - mongo environment: - MONGO_URL=mongodb://mongo:27017/mydb mongo: image: mongo:6 ports: - "27017:27017" volumes: - mongo-data:/data/db volumes: mongo-data: