dockerdockerfiledocker-volume

Docker Compose "The path does not exist" when running `build` but exists when I check inside the container


I have this in my docker-compose.yml

volumes:
  - .:/web
  - /Users/me/libs/my_lib:/app/vendor/libs/my_lib

When I manage to get this image up I can see the volumes are there:

❯ docker inspect -f '{{ .Mounts }}' 9f201ab87498
[{bind  /Users/me/projects/my_project /web  rw true rprivate} {bind  /Users/me/libs/my_lib /app/vendor/libs/my_lib  rw true rprivate}]

When I try to build the docker compose I get this error:

17.16 The path `/app/vendor/libs/my_lib` does not exist.

There is one step in the Dockerfile that is using this path

When I go into the container and look for the folder, the folder exists:

❯ docker compose run project bash
de619d38bc2e:/web# ls -l /app/vendor/libs/my_lib
total 32
[...]

What am I missing?


Docker version 27.0.3, build 7d4bcd8


Solution

  • As it is said on @larsks comment

    The volumes in your compose configuration have absolutely nothing to do with the image building environment. If you expect files to be available during the build process, you must COPY them in using your Dockerfile.

    Using Docker COPY to copy absolute paths is not possible.

    In order to make this work I have to follow these steps:

    You have to copy/hardlink the files/folders inside the directory where you build the docker image