🐳 Docker Beginner

What is Docker Compose?

Answer

Docker Compose is a tool for defining and running multi-container Docker applications using a YAML configuration file (docker-compose.yml or compose.yml). Instead of running long docker run commands for each service, Compose lets you define all services, their configurations, networks, and volumes in one file, then start everything with a single command. Basic docker-compose.yml: version: "3.9"\nservices:\n web:\n build: .\n ports:\n - "3000:3000"\n environment:\n - NODE_ENV=development\n volumes:\n - .:/app\n depends_on:\n - db\n db:\n image: mysql:8.0\n volumes:\n - dbdata:/var/lib/mysql\n environment:\n MYSQL_ROOT_PASSWORD: secret\nvolumes:\n dbdata:. Key commands: docker compose up -d — start all services in background; docker compose down — stop and remove containers; docker compose logs -f web — follow logs; docker compose exec web bash — open shell in running service; docker compose build — rebuild images; docker compose ps — list service status. Services on the same Compose network can reach each other by service name (db, web).