Environment variables are not interpreted in volume driver options in a compose file in Docker Desktop 4.40

Original topic: No volume mounting after Docker Desktop update

I’m having this issue too, after upgrading to Docker Desktop 4.40.0 on macOS 15.4 (2023 MacBook Pro).

The issue seems to be that the bind mount specification in my docker compose file uses an environment variable to specify the host path, but the environment variable seems to be not evaluated / available before the mount specification is parsed:

volumes:
 db_root:
   driver: local
   driver_opts:
     type: none
     device: $STATE_ROOT/database
     o: bind 

If I replace the environment variable $STATE_ROOT with the actual path, everything works as expected:

volumes:
  db_root:
    driver: local
    driver_opts:
      type: none
      device: /Users/fred/projects/example/state/database
      o: bind 

The version with volumes specified with the help of Environment Variables worked in previous versions through 4.38.

In @arpadt’s case, I believe the issue is that Docker Desktop now requires the path specifications to be absolute (so using . to specify the current directory won’t work).

Your issue was completely different, so I moved it out from the original topic to its own.

In your case, the problem is probably how Docker Compose interprets environment variables. It is not Docker Desktop that does it. Docker Desktop just comes with a specific compose version, but you can always download another one if you see the new version is not compatible with your compose files. A least until a bug is fixed in Docker Compose or you can change your compose files if the change was not an introduced bug but an intended change.

https://docs.docker.com/compose/install/linux/#install-the-plugin-manuall

You can find which Docker Desktop comes with which Compose version: https://docs.docker.com/desktop/release-notes/

You can also check the compose release notes:
https://github.com/docker/compose/releases

And if you can make your compose file work again with older compose versions, you can report issues on GitHub in the compose repository, unless the change is shown in the release notes as intended.