Accepted answer

this is just not allowed in the compose file, since you do not have a template engine there.

you will not need to define

volumes: 
        - /opt/h2-data

since that will be done automatically (anonymous volume). if you want to have a named volume use

volumes: 
        - myname:/opt/h2-data

or a host mount

volumes: 
        - /path/on/the/host:/opt/h2-data

so ${data_dir} is not expanded in the volumes ( from the env ) in a compose file. there are dialects like rancher-compose providing this, but in general that is not possible

updated: updated my answer since i somehow mixed the dockerfile/docker-compose.yml file. it makes sense in the dockerfile, since it is just used as a variable. thank you for hinting me on that @bmitch (once again)

sometimes just an extra space can cause the problem (my case): shouldn't be like that:

volumes:
      - ./api/app: /app

but :

volumes:
      - ./api/app:/app
                                            

i had the same error message, it was a silly mistake. i forgot to put the leading forward slash on container directory /app

before

volumes:
      - ./api/app:app

after

volumes:
      - ./api/app:/app
                                

Related Query

  • Docker compose Invalid volume destination path: '.' mount path must be absolute
  • Docker "Invalid mount path app/symfony" must be absolute
  • How to fix invalid mount config for type "bind": source path must be a directory in Windows docker Container?
  • invalid mount path: 'db' mount path must be absolute
  • invalid mount config for type "volume": invalid mount path: 'mongodb-data' mount path must be absolute
  • Derby and WSL2: '.': invalid mount config for type "volume": invalid mount path: 'webappsDB' mount path must be absolute
  • How do I mount a host directory as a volume in docker compose
  • Docker compose how to mount path from one to another container?
  • Docker compose error while creating mount source path
  • Getting invalid mount config for type "bind": bind source path does not exist in docker
  • Docker compose external volume path
  • Docker compose v3: The difference between volume type mount and bind
  • Invalid mount config for type "bind": bind source path does not exist when trying to run container on Docker for Windows
  • Mount docker volume to host machine path
  • includes invalid characters for a local volume name,. If you intended to pass a host directory, use absolute path
  • Docker mount vol error: includes invalid characters for a local volume name
  • Docker compose remote absolute volume
  • How to set absolute path for docker volume in docker-compose?
  • How to mount a docker volume in Azure with docker compose YAML
  • Docker stack deploy with compose-file results in invalid mount config for type "bind": bind source path does not exist:
  • Migrating Docker Compose to Kubernetes Volume Mount Isn't Supported
  • Docker volume mount path
  • Docker compose volume mount ignores the data
  • Docker throwing Invalid Reference format exception when using volume mount
  • Docker Compose volume not mount for mysql image
  • Docker & Docker Compose - COPY for prod image but mount volume for dev
  • How to mount volume in docker compose version '2' format
  • Can't create Docker volume using absolute path on Linux
  • create volume in docker compose base on client directory path
  • container not starting after volume mount in docker compose
  • More Query from same tag

  • Docker says it cannot remove images because a container is running but no containers are running
  • Newman htmlextra reporter complains about newman is missing but it's installed
  • clean docker volume with no reclaimable space on local volumes
  • Does exposing ports in a Dockerfile base image, expose them in a final image?
  • How can I update the latest image that my docker service/stack uses?
  • Developer Package missing in .NET SDK5 docker image
  • Unable to PULL image into minikube from insecure private registry - http: server gave HTTP response to HTTPS client
  • gitlab-ce docker - "PG::ConnectionBad: could not connect to server: No such file or directory"
  • `Protocol Error` when trying to connect Envoy to gRPC service using gRPC Web
  • Spring Boot App Crashes when Scaled By Kubernetes
  • xpra and sudo / what is the difference between sudo and "being a user"
  • error ansible when use docker role
  • Missing files from a dockerfile and issue with running the docker script
  • Unable to connect to nodejs app from react app (inside driver docker app)
  • Opposite command to ENTRYPOINT
  • docker-compose.yml way of setting coredump lengths to unlimited?
  • Is it possible to cache multi-stage docker builds?
  • Need Help Installing TensorFlow Docker Image
  • Celery task .get() not working
  • Monitor dockerised Spring Boot application internals via JMX behind a Kubernetes cluster with VisualVM
  • How to determine IP for containers in host ubuntu machine docker?
  • How to find contents of an NGC Docker image?
  • Docker image not found when running docker push to ECR
  • nginx redirect to docker container
  • How to perform form based authentication in ZAP docker instead headless scanning
  • Apache Spark container startup errors - Docker
  • The usage of Docker base images of Azure Functions
  • Docker Volume Containers for database, logs and metrics
  • not able to perform gcloud init inside dockerfile
  • Docker : using pv (pipe viwer) output nothing on build process
  •