Docker Compose uses a YAML file to define multiple containers and their settings. This lets you start, stop, and manage all containers with simple commands like docker-compose up.
docker-compose up for a valid docker-compose.yml defining two services?version: '3'
services:
web:
image: nginx
db:
image: mysqlWhen docker-compose up runs successfully, it starts the defined services and attaches to their logs, showing messages like 'Starting web ... done'.
web service starts only after the db service is ready?The depends_on key tells Docker Compose to start the db service before web. Other keys like links or wait_for are not valid for this purpose.
app and db. The app service cannot connect to db using the service name as hostname. What is the most likely cause?By default, Docker Compose creates a single network for all services, allowing them to communicate by service name. If services are on different networks, they cannot resolve each other.
First, docker-compose pull updates images. Then docker-compose down stops and removes containers. Next, docker-compose up -d starts containers with new images. Finally, docker-compose ps shows running containers.