Docker & Containers (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
What is Docker Compose, and when is it used instead of raw Docker commands?
junior LevelMost AskedCode ExampleDocker & Containers
In Simple Words:
Docker Compose is a declarative tool for defining and running multi-container Docker applications using a single YAML file (docker-compose.yml).
- Instead of running 5 separate
docker runcommands with complex network, environment, and volume flags, a singledocker compose up -dbrings up all services (e.g., API backend, PostgreSQL database, Redis cache, frontend proxy) together on a shared private network.
yaml
version: '3.8'
services:
web:
build: .
ports:
- "3000:3000"
environment:
- DATABASE_URL=postgres://user:pass@db:5432/mydb
depends_on:
- db
db:
image: postgres:16-alpine
environment:
POSTGRES_PASSWORD: pass
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata: