# WARNING: The 'version' attribute in docker-compose.yml is obsolete. Use 'services' directly without 'version'.

- **ID:** `docker/compose-version-attribute-obsolete`
- **Domain:** docker
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 95%

## Root Cause

Docker Compose v2.20+ no longer supports the 'version' top-level key; it was used in legacy Compose v1 files and is now ignored or causes a warning.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Docker Compose v2.20.0 | active | — | — |
| Docker Compose v2.21.0 | active | — | — |
| Docker Compose v2.22.0 | active | — | — |
| Docker Desktop 4.24.0 | active | — | — |

## Workarounds

1. **Remove the 'version' line from docker-compose.yml entirely. The file should start with 'services:' directly. Example: replace 'version: "3.8"\nservices:' with 'services:'.** (95% success)
   ```
   Remove the 'version' line from docker-compose.yml entirely. The file should start with 'services:' directly. Example: replace 'version: "3.8"\nservices:' with 'services:'.
   ```
2. **If you need to support both Compose v1 and v2, use a conditional check in your CI/CD: 'if docker compose version | grep -q v2; then sed -i '/^version:/d' docker-compose.yml; fi'.** (85% success)
   ```
   If you need to support both Compose v1 and v2, use a conditional check in your CI/CD: 'if docker compose version | grep -q v2; then sed -i '/^version:/d' docker-compose.yml; fi'.
   ```
3. **Use 'docker compose config' to validate and migrate your file: it will output the normalized config without the 'version' attribute, which you can redirect to a new file.** (90% success)
   ```
   Use 'docker compose config' to validate and migrate your file: it will output the normalized config without the 'version' attribute, which you can redirect to a new file.
   ```

## Dead Ends

- **Updating the 'version' value to '3.9' or '3.8' thinking it is a version mismatch** — The warning is not about the version number being wrong; the entire attribute is deprecated. Changing the value does not remove the warning. (95% fail)
- **Ignoring the warning because 'docker compose up' still works** — While the warning does not prevent execution, future versions of Docker Compose may treat the presence of 'version' as a fatal error, breaking the setup. (40% fail)
- **Downgrading Docker Compose to v1 to keep using the 'version' attribute** — Docker Compose v1 is deprecated and no longer receives security updates; downgrading introduces risks and is not a sustainable solution. (70% fail)
