compose: volume driver_opts device does not allow relative paths
Docker-compose allows relative paths for most volume commands but does not support such paths when used under driver_opts device
Output of docker-compose version
docker-compose version 1.22.0, build f46880fe
docker-py version: 3.4.1
CPython version: 3.6.6
OpenSSL version: OpenSSL 1.0.2o 27 Mar 201
Output of docker version
Client:
Version: 18.06.1-ce
API version: 1.38
Go version: go1.10.3
Git commit: e68fc7a
Built: Tue Aug 21 17:21:34 2018
OS/Arch: windows/amd64
Experimental: false
Server:
Engine:
Version: 18.06.1-ce
API version: 1.38 (minimum version 1.12)
Go version: go1.10.3
Git commit: e68fc7a
Built: Tue Aug 21 17:29:02 2018
OS/Arch: linux/amd64
Experimental: false
Output of docker-compose config
(Make sure to add the relevant -f
and other flags)
services:
foo:
image: nginx
volumes:
- source: C:\mydir\foo
target: /foo
type: bind
- source: foo2
target: /foo2
type: volume
version: '3.7'
volumes:
foo2:
driver: local
driver_opts:
device: ./foo2
o: bind
type: none
Steps to reproduce the issue
- Attempt to use a relative path under driver_opts device
version: "3.7"
services:
foo:
image: nginx
volumes:
- type: bind
source: ./foo
target: /foo
- type: volume
source: foo2
target: /foo2
volumes:
foo2:
driver: local
driver_opts:
type: none
o: bind
device: ./foo2
- docker-compose up
Creating volume "mydir_foo2" with local driver
Creating mydir_foo_1 ... error
ERROR: for mydir_foo_1 Cannot start service foo: error while mounting volume '': error while mounting volume with options: type='none' device='./foo2' o='bind': no such file or directory
ERROR: for foo Cannot start service foo: error while mounting volume '': error while mounting volume with options: type='none' device='./foo2' o='bind': no such file or directory
ERROR: Encountered errors while bringing up the project.
providing a full path using /c/ notation corrects the problem.
Expected result
Compose should determine the proper path using the same expansion ;ogic as done for the usual bind mount relative paths.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 36
- Comments: 18
This issue has been automatically closed because it had not recent activity during the stale period.
${PWD}
isn’t an option at all cause it depend too strongly on the context.sudo
the docker commands. Then byebye the PWD variable.-f ./ops/dev/docker-compose.yml
then byebye the true PWD variableThis feature must be implemented cause there is no alternatives.
I achieved this a while back using the native “$PWD” variable (Linux & Mac). This does not require a custom environment file. So it can be easily achieved using the below syntax. I agree though that they should conform with the other bind syntax and allow for your example. In the meantime, this works well.
Edit: I believe ${PWD} will work cross-platform, but I don’t have a windows docker environment to test this. Hopefully, this helps someone else.
It’s 2020 and this issue from 2018 still persists.
How do we reopen it?
I’m dearly, dearly missing this option. It’s hard to handle a lot of volumes if they can’t be named, and
${PWD}
isnt an option, since it’s not cross-platform.nice to have this feature
@aiordache What do you think? @Eluminae concerns here seems very reasonable.
there is no real alternatives.
Thanks for the blog post, all efforts are helpful.
I though think the point of the ticket remains to request that docker-compose should do all this bending-over-backwards for the user. I mean it does exactly this in other places determining the relative path regardless of operating system without the need for squirrelly custom environmental variables.
To my knowledge compose does not do anything we could not script out step-by-step on our own were we so inclined. Rather we use compose cause it makes complicated things easier and simpler to execute. This request is that compose “do its thing” for the bind device pointer and allow us to provide relative paths that compose then converts to an absolute address internally.
That would be swell.
http://blog.code4hire.com/2018/06/define-named-volume-with-host-mount-in-the-docker-compose-file/
Sorry, my English is very bad. I stumbled upon this article, hope it helps you.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Sadly the windows powershell equivalent is lower case $pwd and the equivalent in windows command shell would be the cd command. Those details are generally why we’d want docker-compose to handle this for us. I mean compose already has the logic to know where things are at for other options that take a dot, so the request here to just expand that to the device option.
Same problem:
Same problem in Ubuntu 18.04 with docker compose version
docker-compose.yml
I agree this would be nice and could save some head-scratching. The current functionality (driver options passed through directly to drivers) is documented, although it took me a little while to find it. The consistency and ease of use might be worth the addition of path expansion logic.