Search code examples
dockerdocker-composedockerfilemountdocker-container

Docker Mount Configuration Container Creation Error


I'm trying to create a container from a docker image for a project I'm working on (project sidewalk). The container spins up correctly except for the last step where it gives me this error:

Creating projectsidewalk-db ... error                                                                                   
ERROR: for projectsidewalk-db  Cannot create container for service db: invalid volume specification: 'C:\Users\johns\OneDrive\documents\GitHub\sidewalkwebpage\db\init.sh:/docker-entrypoint-initdb.d/init.sh:rw': 
invalid mount config for type "bind": source path must be a directory

ERROR: for db  Cannot create container for service db: invalid volume specification: 'C:\Users\johns\OneDrive\documents\GitHub\sidewalkwebpage\db\init.sh:/docker-entrypoint initdb.d/init.sh:rw': 
invalid mount config for type "bind": source path must be a directory
ERROR: Encountered errors while bringing up the project.
make: *** [docker-up-db] Error 1

I've looked on other Stack Overflow threads and I've tried the fix where I create a new variable COMPOSE_CONVERT_WINDOWS_PATHS and set it equal to one, but it didn't work. I was wondering if anyone knows how to fix this problem.


Solution

  • You cannot mount files on Windows, only directories are permitted. There was an issue for this in moby which was closed unresolved, because this is actually a limitation of Windows, not Docker: https://github.com/moby/moby/issues/30555#issuecomment-279170073.

    Wrapping up: I guess you have something like this in your docker-compose.yml:

    volumes:
    - .\db\init.sh:/docker-entrypoint-initdb.d/init.sh:rw
    

    it should be this instead:

    volumes:
    - .\db:/docker-entrypoint-initdb.d/:rw