wasAsked.

What is the difference between Docker and Docker Compose?

Frequently Asked (All Companies) · Role not specified · technical

Published

Year not specified · Docker

Community answers

Posted by wasAsked editorial collection

Docker is the platform for building and running containers. Docker Compose is a tool, built on Docker, for defining and running applications made of multiple containers with a single configuration file. Docker (Docker Engine and CLI) - Builds images from Dockerfiles and runs individual containers: docker network create shop-net docker run -d --name db --network shop-net -e POSTGRES_PASSWORD=secret -v pgdata:/var/lib/postgresql/data postgres:16 docker run -d --name api --network shop-net -p 8080:8080 -e ConnectionStrings__Db="Host=db;Password=secret" orders-api:1.0 - Each container is started with its own command and options; coordinating many containers manually becomes error-prone. Docker Compose - Describes the whole multi-container application declaratively in compose.yaml (formerly docker-compose.yml): services, images or build contexts, ports, environment variables, volumes, networks and dependencies. services: db: image: postgres:16 environment: POSTGRES_PASSWORD: secret volumes: - pgdata:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U postgres"] interval: 5s api: build: ./src/Orders.Api ports: - "8080:8080" environment: ConnectionStrings__Db: "Host=db;Password=secret" depends_on: db: condition: service_healthy volumes: pgdata: - Commands: docker compose up -d # build if needed and start everything docker compose logs -f api # follow logs docker compose down # stop and remove containers (add -v to remove volumes) - Compose creates a shared network automatically, so services reach each other by service name (Host=db). - Compose V2 is integrated into the Docker CLI as "docker compose" (the older docker-compose Python tool is retired). Key differences - Scope: Docker manages individual containers and images; Compose manages a group of related containers as one application. - Configuration: Docker uses CLI flags per container; Compose uses a version-controlled YAML file. - Networking: with Docker you create networks manually; Compose creates them for you. - Startup order and health: Compose supports depends_on with health conditions. Typical uses of Compose - Local development: run the API, database, cache and message broker together with one command. - Integration testing in CI pipelines. - Simple single-host deployments. Limitations Compose runs on a single host and does not provide cluster scheduling, self-healing across machines or advanced rolling updates. For production at scale, use an orchestrator such as Kubernetes or a managed container platform (Azure Container Apps, Amazon ECS). Docker Swarm can use Compose files but is less common today. .NET developers may also use .NET Aspire for local orchestration of multi-service apps, which can generate deployment manifests. Interview summary: "Docker builds and runs containers; Docker Compose describes and runs a multi-container application from one YAML file, handling networks, volumes and dependencies — ideal for local development and testing."

Ravindra Wadile · · 0 likes

Sign in to add your answer

Related interview topics