Understanding the syntax: services, image, build, ports, volumes, and environment.
The `docker-compose.yml` file is the heart of Docker Compose. It's a YAML file that defines a multi-service application. The top-level key is usually `services`, under which you list each of your application's components. Each service is given a name, like `web` or `api`. Under each service name, you define its configuration. The `image` key specifies the Docker image to use, like `image: node:18`. Alternatively, you can use the `build` key to specify the path to a directory containing a Dockerfile, which tells Compose to build a custom image for that service (e.g., `build: .`). The `ports` key maps ports from the host to the service's container in a `HOST:CONTAINER` format. To persist data, the `volumes` key is used to mount either named volumes or host paths into the container. A very common key is `environment`, which allows you to pass environment variables into the container. This is the standard way to provide configuration details like database passwords or API keys without hard-coding them into your Docker image. By combining these keys, you can declaratively define a complex application with multiple interconnected services, making the entire setup portable and easy to manage.