It seems this question has already been asked by another poster, but there was no answer. I have more information on the matter, so I'm re-asking the same question - but with much additional material.
I'm running Docker on Windows 10. I have Docker configured for using Linux containers (not Windows containers). I have my C drive configured as a shared drive.
The Problem
I have the following docker-compose file called wp.yml
:
version: '3.2'
services:
db:
image: mysql:5.7
volumes:
- type: volume
source: wp_dbA
target: /var/lib/mysql
restart: always
volumes:
wp_dbA:
driver_opts:
type: none
device: ./wp-db
o: bind
I execute as follows:
c:\repos\wpsand\wpA> docker-compose -f wp.yml up -d
I receive the following error:
ERROR: for wpa_db_1 Cannot create container for service db: error while mounting volume with options: type='none' device='./wp-db' o='bind': no such file or directory
ERROR: for db Cannot create container for service db: error while mounting volume with options: type='none' device='./wp-db' o='bind': no such file or directory ERROR: Encountered errors while bringing up the project.
Despite the message,the folder wp-db
does already exist, located here:
c:/repos/wpsand/wpA/wp-db
Clues...
Despite the above error, checking docker volume ls
reveals that volume wpa_wp_dbA
was freshly created.
Clue #1
If I change the shared volume device
to use an absolute path (such as /c/repos/wpsand/wpA
), then run again...I get the same problem. However, the error message still says that device with relative path ./wp-db
cannot be found.
Apparently the re-use of the shared volume named wp_dbA
causes any newly specified path to be ignored. The original ./wp-db
is what it will attempt to use.
Clue #2
If I revert back to a relative path, but change the name of the shared volume to "wp_dbB", I still get the same error.
Clue #3
This combines #1 and #2 above. If I invent a new shared volume name, and use an absolute path, it works! My container is launched successfully. Unfortunately, I'm no longer using the relative path I wanted.
Clue #4
Now that my container works, I docker-compose down
and change the docker-compose file again. I put the relative path back in, and "compose up". It works!
Conclusion?
It looks like relative paths simply don't work. But I've been seeing docker-compose files posted online using this same shared volume relative path notation. Perhaps it works for Docker, but not Docker on Windows?
Can anyone suggest a work-around?
Update!
I found this SO post that very nearly has a relative-path work-around. I updated my compose file to use the ${PWD}
notation, and launched it from my Git Bash shell. Now I got this error:
$ docker-compose up -d
Creating wpa_db_1 ... error
Creating wpa_db_1 ...
ERROR: for wpa_db_1 Cannot create container for service db: error
while mounting volume with options: type='none'
device='C:/repos/wpsand/wpA/wp-db' o='bind': no such file or directory
ERROR: for db Cannot create container for service db: error while
mounting volume with options: type='none' device='C:/repos/wpsand/wpA/wp-db'
o='bind': no such file or directory
Encountered errors while bringing up the project.
That almost worked! If only the ${PWD}
had expanded into a Linux mount notation (/c/repos/wpsand/wpA/wp-db
)!