0

It's probably a very simple thing. I just can't seem to get an answer by googling. I keep getting error when using Docker-Compose to mount a folder 2 level down of my current folder as a volume into a container.

I'm running Docker on Windows 10. I got two containers. The first one does some web scraping and generates a table in html and dump it into the mounted volume. The 2nd container runs flask and present the html through web portal.

By default the flask container loads html files from its templates folder. So for the scraper container, I tries to mount a volume points to that templates folder. But as soon as I put more than 2 levels of path in the mount path, the container will just fail to run with this error:

invalid mount config for type "volume": invalid mount path: 'static' mount path must be absolute

I then tried put in the absolute path as indicated, but getting the same error.

volumes:
      - 'C:/shared/project/testProject/webfront/templates:/usr/src/app/data'

Here is docker-compose file snippet

  scraper:
    build: './scraper'
    env_file:
      - '.env'
    volumes:
      - './webfront/templates:/usr/src/app/data'

Here's the folder structure

./
├───scraper
└───webfront
    ├───templates

I have tested mounting the volume with docker run command, and was able to mount the volume successfully after provided the absolute path. So it appears this is an issue/bug to do with docker-compose only. I will try raise a issue in their Github repo.

Tomking Chen
  • 343
  • 3
  • 17
  • 1
    try using complete(absoulte) path instead of relevent path, like if you are on linux machine use `pwd` comand on termianal to get absolute path for that directory – Ganesh Karewad Jul 18 '19 at 10:19
  • I have already tried that. Updated the description with code snippet to show. – Tomking Chen Jul 19 '19 at 00:58
  • this might be helpful https://stackoverflow.com/questions/23439126/how-to-mount-a-host-directory-in-a-docker-container – Ganesh Karewad Jul 19 '19 at 06:01
  • 1
    It turns out the problem is my lack of understanding how docker-compose works. As after I changed the volume path in docker-compose.yaml file, I need to **remove the old images**, instead of rerun `docker-compose up` command. After the images are properly rebuilt with the absolute path, the volume was then mounted correctly. – Tomking Chen Jul 22 '19 at 06:06

0 Answers0