Skip to content

Conversation

@leoperegrino
Copy link
Contributor

What I did
Implemented volumes command with:

  • GO template support
  • service filtering
  • test cases
  • docs update.

Given the following compose files:

# compose_1.yaml
name: compose_1

volumes:
  vol_1:
  vol_2:
  vol_3:

services:

  service_1:
    image: gcr.io/google-containers/pause
    restart: no
    volumes:
      - vol_1:/tmp/vol_1
      - vol_2:/tmp/vol_2

  service_2:
    image: gcr.io/google-containers/pause
    restart: no
    volumes:
      - vol_3:/tmp/vol_3
# compose_2.yaml
name: compose_2

volumes:
  vol_1:
  # not used
  vol_2:

services:

  service_1:
    image: gcr.io/google-containers/pause
    restart: no
    volumes:
      - vol_1:/tmp/vol_1

The following manual tests should hold:

docker compose -f compose_1.yaml up -d
docker compose -f compose_2.yaml up -d

docker volume ls
# DRIVER    VOLUME NAME
# local     compose_1_vol_1
# local     compose_1_vol_2
# local     compose_1_vol_3
# local     compose_2_vol_1
# local     compose_2_vol_2

docker compose -f compose_1.yaml volumes
# DRIVER    VOLUME NAME
# local     compose_1_vol_1
# local     compose_1_vol_2
# local     compose_1_vol_3

docker compose -f compose_1.yaml volumes service_1
# DRIVER    VOLUME NAME
# local     compose_1_vol_1
# local     compose_1_vol_2

docker compose -f compose_1.yaml volumes service_2
# DRIVER    VOLUME NAME
# local     compose_1_vol_3

docker compose -f compose_1.yaml volumes service_1 service_2
# DRIVER    VOLUME NAME
# local     compose_1_vol_1
# local     compose_1_vol_2
# local     compose_1_vol_3

docker compose -f compose_2.yaml volumes
# DRIVER    VOLUME NAME
# local     compose_2_vol_1

docker compose -f compose_2.yaml volumes service_1
# DRIVER    VOLUME NAME
# local     compose_2_vol_1

docker compose -f compose_2.yaml volumes wrong_service_name
# no such service: wrong_service_name

docker compose -f compose_1.yaml volumes --format 'table {{.Name}}'
# VOLUME NAME
# compose_1_vol_1
# compose_1_vol_3
# compose_1_vol_2

docker compose -f compose_1.yaml volumes --format json
# {"Availability":"N/A","Driver":"local","Group":"N/A","Labels":"com.docker.compose.project=compose_1,com.docker.compose.version=2.36.0,com.docker.compose.volume=vol_3,com.docker.compose.config-hash=4b9e9f43e5d7acc8216829918e68c3e509add0e7e0314f287b6619be566c50f1","Links":"N/A","Mountpoint":"/var/lib/docker/volumes/compose_1_vol_3/_data","Name":"compose_1_vol_3","Scope":"local","Size":"N/A","Status":"N/A"}
# {"Availability":"N/A","Driver":"local","Group":"N/A","Labels":"com.docker.compose.config-hash=2dfb8b5aea067aa119a8c5e855f68412522bebd53b3d6e685b2322e5dfdc892d,com.docker.compose.project=compose_1,com.docker.compose.version=2.36.0,com.docker.compose.volume=vol_1","Links":"N/A","Mountpoint":"/var/lib/docker/volumes/compose_1_vol_1/_data","Name":"compose_1_vol_1","Scope":"local","Size":"N/A","Status":"N/A"}
# {"Availability":"N/A","Driver":"local","Group":"N/A","Labels":"com.docker.compose.version=2.36.0,com.docker.compose.volume=vol_2,com.docker.compose.config-hash=ab52462cd8693689c92819e3115b636c9df42021828d0aeda344b185185e9f2a,com.docker.compose.project=compose_1","Links":"N/A","Mountpoint":"/var/lib/docker/volumes/compose_1_vol_2/_data","Name":"compose_1_vol_2","Scope":"local","Size":"N/A","Status":"N/A"}

Remarks:

  • a volume declared in the compose but not used will not appear, as shown before with compose_2_vol_2
  • should this be marked as experimental?

Related issue

This closes #11111

@leoperegrino leoperegrino requested a review from a team as a code owner June 18, 2025 15:36
@leoperegrino leoperegrino requested review from glours and ndeloof June 18, 2025 15:36
@leoperegrino leoperegrino force-pushed the volumes_command branch 2 times, most recently from 7ce9f2e to 17719c3 Compare June 18, 2025 18:35
@leoperegrino
Copy link
Contributor Author

@ndeloof do you know why those e2e tests are failing? the other PRs seem to have skipped those.
Locally, docker compose -f ./fixtures/cascade/compose.yaml --project-name compose-e2e-cascade-fail up --abort-on-container-failure is running fine and the return code is 111, not 143.

Signed-off-by: Leonardo Peregrino <[email protected]>
Signed-off-by: Leonardo Peregrino <[email protected]>
Signed-off-by: Leonardo Peregrino <[email protected]>
Signed-off-by: Leonardo Peregrino <[email protected]>
@ndeloof ndeloof enabled auto-merge (rebase) June 30, 2025 17:26
@ndeloof ndeloof merged commit 6198ed5 into docker:main Jun 30, 2025
27 checks passed
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Jul 6, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [docker/compose](https://github.com/docker/compose) | minor | `v2.37.3` -> `v2.38.1` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>docker/compose (docker/compose)</summary>

### [`v2.38.1`](https://github.com/docker/compose/releases/tag/v2.38.1)

[Compare Source](docker/compose@v2.38.0...v2.38.1)

#### What's Changed

##### ✨ Improvements

- implement `model_variable` by [@&#8203;ndeloof](https://github.com/ndeloof) in docker/compose#13001

##### ⚙️ Dependencies

- bump compose-go to version v2.7.1 by [@&#8203;glours](https://github.com/glours) in docker/compose#13000

**Full Changelog**: docker/compose@v2.38.0...v2.38.1

### [`v2.38.0`](https://github.com/docker/compose/releases/tag/v2.38.0)

[Compare Source](docker/compose@v2.37.3...v2.38.0)

#### What's Changed

##### ✨ Improvements

- introduce support for models by [@&#8203;ndeloof](https://github.com/ndeloof) in docker/compose#12976
- Add volumes command by [@&#8203;leoperegrino](https://github.com/leoperegrino) in docker/compose#12954
- remove publish limitation on bind mount by [@&#8203;glours](https://github.com/glours) in docker/compose#12997
- mount /var/run/docker.sock for --use-api-socket by [@&#8203;ndeloof](https://github.com/ndeloof) in docker/compose#12995

##### 🐛 Fixes

- only expose API socket to service asking for it by [@&#8203;ndeloof](https://github.com/ndeloof) in docker/compose#12972
- check progress default value instead of empty string to use BUILDKIT\_PROGRESS env variable value by [@&#8203;glours](https://github.com/glours) in docker/compose#12982
- exclude provider services from the list of dependencies that Compose should wait for by [@&#8203;glours](https://github.com/glours) in docker/compose#12983
- don't fail down cmd if services with pre\_stop hook already stopped/removed by [@&#8203;glours](https://github.com/glours) in docker/compose#12986
- Swap to Reader in bake to avoid hangs on output by [@&#8203;nscott](https://github.com/nscott) in docker/compose#12984
- make sure the post\_start hooks fails by [@&#8203;glours](https://github.com/glours) in docker/compose#12996
- remove error message from exec outpout by default by [@&#8203;glours](https://github.com/glours) in docker/compose#12992
- fix: typos by [@&#8203;hezhizhen](https://github.com/hezhizhen) in docker/compose#12963
- pass project.environment to bake by [@&#8203;ndeloof](https://github.com/ndeloof) in docker/compose#12994
- fix provider concurrent environment map accesses by [@&#8203;glours](https://github.com/glours) in docker/compose#12999
- e2e compose run --env by [@&#8203;ndeloof](https://github.com/ndeloof) in docker/compose#12967

##### ⚙️ Dependencies

- build(deps): bump github.com/docker/cli from 28.2.2+incompatible to 28.3.0+incompatible by [@&#8203;dependabot](https://github.com/dependabot) in docker/compose#12974
- build(deps): bump github.com/docker/docker from 28.2.2+incompatible to 28.3.0+incompatible by [@&#8203;dependabot](https://github.com/dependabot) in docker/compose#12975

#### New Contributors

- [@&#8203;nscott](https://github.com/nscott) made their first contribution in docker/compose#12984
- [@&#8203;hezhizhen](https://github.com/hezhizhen) made their first contribution in docker/compose#12963
- [@&#8203;leoperegrino](https://github.com/leoperegrino) made their first contribution in docker/compose#12954

**Full Changelog**: docker/compose@v2.37.3...v2.38.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MC42Mi4xIiwidXBkYXRlZEluVmVyIjoiNDAuNjIuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
@renovate renovate bot mentioned this pull request Jul 21, 2025
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants