Start Compose services detached and view one service's logs
basic Compose CLI usage.
docker compose up -d starts everything detached; docker compose logs -f web follows only the web service's logs.
WHAT THIS TESTS It checks fluency with the Compose lifecycle commands and the distinction between Compose service names and raw container references.
A GOOD ANSWER COVERS To start everything in the background: docker compose up -d. This creates the default network, builds images where a build directive exists, and runs every service detached so your terminal returns. To view logs for just one service: docker compose logs web, where web is the service key from the YAML; add -f to follow in real time and --tail=100 to bound history. The Compose CLI resolves the service name to its container, aggregating logs even if the service is scaled to multiple replicas. A strong candidate notes that modern Docker uses the compose subcommand (docker compose) rather than the legacy docker-compose binary.
COMMON WRONG ANSWERS Using docker logs web, which treats web as a container name and may not match the Compose-generated container name. Omitting -d and tying up the shell. Confusing docker compose logs with docker compose up output, or thinking you must grep a combined log stream.
LIKELY FOLLOW-UPS How do you follow logs for all services versus one? What is the difference between docker compose and docker-compose? How do you stop and remove everything with down?
ONE CONCRETE EXAMPLE With a web and a db service defined, docker compose up -d brings both up in the background. While debugging a request error you run docker compose logs -f web and watch only the web app's request logs stream, without the database's noisy startup output mixed in.
Read the original → docs.docker.com
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.