2

Trying to set relative path to mount files, but it adding to path folder in which he is(compose file).

  liquibase:
    image: liquibase/liquibase
    volumes:
      - ./resources/changelog:/liquibase/changelog
    command: --changeLogFile=master.xml --url=jdbc:postgresql://postgres:5432/postgres?autoReconnect=true&useSSL=false --username=postgres --password=password update
    depends_on:
      - postgres
    networks:
      - my_network

With ./ path: app\docker\resources\changelog here extra folder 'docker', there is docker-compose file.

I expect app\resources\changelog, how I can set correct relative path?

Max
  • 253
  • 2
  • 16

1 Answers1

6

Most paths in the docker-compose.yml file, including volumes: bind mount locations, are relative to the Compose file's location. If you have multiple Compose files they are relative to the first one. Conversely, there's no restriction against using relative paths or .. to go to a parent directory.

So if your directory layout is

app
+-- docker
|   \-- docker-compose.yml
\-- resources
    \-- changelog

and from the app directory you're running

docker-compose -f docker/docker-compose.yml up

the volumes: paths are resolved relative to the Compose file's location, not the current directory, so you can specify

volumes:
  - ../resources/changelog:/liquibase/changelog

(Within a Dockerfile, the COPY directive can only look inside the build context directory, and can't use .. to step out of it, but that's specific to the image build. The usual solution to this is to specify build: .. or something similar in the Compose file so that the build context is the parent of any directory that contains files that need to be included.)

David Maze
  • 130,717
  • 29
  • 175
  • 215