Skip to content

Enable relative paths for driver_opts.device#7762

Merged
ulyssessouza merged 2 commits intodocker:masterfrom
aiordache:relative_path_driver_opts
Sep 16, 2020
Merged

Enable relative paths for driver_opts.device#7762
ulyssessouza merged 2 commits intodocker:masterfrom
aiordache:relative_path_driver_opts

Conversation

@aiordache
Copy link
Contributor

@aiordache aiordache commented Sep 14, 2020

The driver options for a volume are forwarded to the docker engine unmodified (as specified in the compose file). #6343 requests support for relative paths in the 'device' option of the local driver.
This patch converts the relative paths for driver_opts.device to absolute paths (only for a local driver and bind mount option).

docker-compose.yml

version: '3.8'
services:
  app:
    image: nginx
    volumes:
      - vol:/test
volumes:
  vol:
    driver_opts:
      type: none
      o: bind
      device: .
$ pwd
/home/anca/compose/test
$ ls
docker-compose.yml

$ docker-compose up -d

$ docker volume ls
DRIVER              VOLUME NAME
local               test_vol

$ docker volume inspect test_vol
[
    {
        "CreatedAt": "2020-09-03T14:52:50+02:00",
        "Driver": "local",
        "Labels": {
            "com.docker.compose.project": "test",
            "com.docker.compose.version": "1.28.0dev",
            "com.docker.compose.volume": "vol"
        },
        "Mountpoint": "/home/anca/.local/docker/volumes/test_vol/_data",
        "Name": "test_vol",
        "Options": {
            "device": "/home/anca/compose/test",
            "o": "bind",
            "type": "none"
        },
        "Scope": "local"
    }
]

$ docker exec -t  test_app_1 sh -c "ls /test"
docker-compose.yml

Resolves #6343

Signed-off-by: aiordache <anca.iordache@docker.com>
@aiordache aiordache added this to the 1.27.3 milestone Sep 14, 2020
Signed-off-by: aiordache <anca.iordache@docker.com>
return
o = config['driver_opts'].get('o')
device = config['driver_opts'].get('device')
if o and o == 'bind' and device:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
if o and o == 'bind' and device:
if o == 'bind' and device:

Copy link
Contributor

@ulyssessouza ulyssessouza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ulyssessouza ulyssessouza merged commit c960b02 into docker:master Sep 16, 2020
@maaarghk
Copy link

maaarghk commented Oct 8, 2020

Please see #7856, I believe this introduced a BC break on a point release. The check for existing volumes with different "driver_opts.device" value needs updated to check resolved path returned from the daemon.

@djherbis
Copy link

@aiordache I think there's another related regression affecting me because of this.

I execute docker-compose on Windows, with a remote docker host on Linux. The expansion/abs path transformation ends up converting Linux absolute paths (like /path/from/root), into Windows-style paths (like C:/path/from/root), which ends up as an invalid path on the remote filesystem (and caused my volumes to report that the 'device' changed even though I haven't changed my docker-compose file in years).

Anything we can do to fix this? Maybe don't try to normalize these paths when you're not talking to a local docker daemon, since the filesystem is totally different?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

volume driver_opts device does not allow relative paths

4 participants