This repository demonstrates how to replace multiple Docker commands with a Docker Compose configuration for a simpler development environment setup.
Previously, we had to run multiple Docker commands separately:
docker network create goals-net
docker run --name mongodb \
-e MONGO_INITDB_ROOT_USERNAME=cagatay \
-e MONGO_INITDB_ROOT_PASSWORD=secret \
-v data:/data/db \
--rm \
-d \
--network goals-net \
mongo
docker build -t goals-node .
docker run --name goals-backend \
-e MONGODB_USERNAME=<username> \
-e MONGODB_PASSWORD=<password> \
-v logs:/app/logs \
-v /<projectLocalPath>/backend:/app \
-v /app/node_modules \
--rm \
-d \
--network goals-net \
-p 80:80 \
goals-node
docker build -t goals-react .
docker run --name goals-frontend \
-v /<projectLocalPath>/frontend/src:/app/src \
--rm \
-d \
-p 3000:3000 \
-it \
goals-react
docker stop mongodb goals-backend goals-frontend
Now, all these commands are replaced with a single docker-compose.yml
file:
docker-compose up -d
-
Simplified Commands: Instead of running multiple Docker commands, we now use single commands
- Start all services:
docker-compose up -d
- Stop all services:
docker-compose down
- View logs:
docker-compose logs
- Start all services:
-
Automatic Network Creation: Docker Compose automatically creates and manages networks
-
Dependencies Management: Services can be configured to wait for other services using
depends_on
-
Environment Consistency: All team members use the same configuration
- Docker
- Docker Compose
- Git
- Clone the repository:
git clone [repository-url]
cd [repository-name]
- Start the environment:
docker-compose up -d
- Application (Node.js) - Port 80
- Mongodb - Port 27017
- React SPA - Port 3000