Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 DOWNLOAD http://www.h2database.com/h2-2016-10-31.zip
ENV DATA_DIR /opt/h2-data

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

EXPOSE 8082 9092

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

VOLUME ${DATA_DIR}

Following is the docker compose i am trying to perform:

version: '2'


services:
    db:
        image: klousiaj/oracle-java:7.79
        environment: 
            DOWNLOAD: http://www.h2database.com/h2-2016-10-31.zip
            DATA_DIR: /opt/h2-data
        command: curl ${DOWNLOAD} -o h2.zip \ && unzip h2.zip -d /opt/ \ && rm h2.zip \ && mkdir -p ${DATA_DIR}
        expose: 
            - "8082-9092"
        command: java -cp /opt/h2/bin/h2*.jar org.h2.tools.Server \ -web -webAllowOthers -webPort 8082 \ -tcp -tcpAllowOthers -tcpPort 9092 \ -baseDir ${DATA_DIR}
        volumes: 
            - ${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.

like image 837
Shan Khan Avatar asked Jan 03 '17 14:01

Shan Khan


3 Answers

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
like image 161
Collin Thomas Avatar answered Oct 09 '22 04:10

Collin Thomas


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)

like image 41
Eugen Mayer Avatar answered Oct 09 '22 03:10

Eugen Mayer


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
like image 2
Tazi Rida Avatar answered Oct 09 '22 04:10

Tazi Rida