Docker compose Invalid volume destination path: '.' mount path must be absolute

Following is my dockerfile that works to run the H2 Database:
I want to create a docker compose file for this.

FROM klousiaj/oracle-java:7.79
MAINTAINER J.P. Klousia <klousiaj>

ENV DATA_DIR /opt/h2-data

RUN curl ${DOWNLOAD} -o \
    && unzip -d /opt/ \
    && rm \
    && mkdir -p ${DATA_DIR}

EXPOSE 8082 9092

CMD java -cp /opt/h2/bin/h2*.jar \
    -web -webAllowOthers -webPort 8082 \
    -tcp -tcpAllowOthers -tcpPort 9092 \
    -baseDir ${DATA_DIR}


Following is the docker compose i am trying to perform:

  • AWS Elastic Beanstalk Docker environment variables
  • jekyll not updating static CSS, HTML files in docker development container
  • Replacing sbt-native-packager with sbt-docker in Scala Play
  • docker running in vmware gets x509 error
  • Different localhost ports causes failed Access-Control-Allow-Origin
  • Run Java command line from node.js dokku container
  • version: '2'
            image: klousiaj/oracle-java:7.79
                DATA_DIR: /opt/h2-data
            command: curl ${DOWNLOAD} -o \ && unzip -d /opt/ \ && rm \ && mkdir -p ${DATA_DIR}
                - "8082-9092"
            command: java -cp /opt/h2/bin/h2*.jar \ -web -webAllowOthers -webPort 8082 \ -tcp -tcpAllowOthers -tcpPort 9092 \ -baseDir ${DATA_DIR}
                - ${DATA_DIR}

    Im getting error as :

    ERROR: for db Cannot create container for service db: Invalid volume spec “.”: Invalid volume destination path: ‘.’ mount path must be absolute.

  • Deploying docker-compose containers
  • How can I resolve the error oci runtime error: exec: no such file or directory when using docker run on Windows
  • Cannot install packages inside docker Ubuntu image
  • Docker init Daemon best practices (PID 1 zombie reaping)
  • How to enable the Docker Remote API on Windows
  • Starting a process in the Dockerfile
  • One Solution collect form web for “Docker compose Invalid volume destination path: '.' mount path must be absolute”

    This is just not allowed in the Compose file, since you do not have a template engine thee.

    You will not need to define

            - /opt/h2-data

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

            - myname:/opt/h2-data

    or a host mount

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

    So ${DATA_DIR} is not expaneded 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 forhinting me on that @Bmitch (once again)

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.