Moby: cannot mount a host file using relative path

Created on 7 Jul 2016  路  3Comments  路  Source: moby/moby

BUG REPORT INFORMATION

Output of docker version:

Client:
 Version:      1.11.1
 API version:  1.23
 Go version:   go1.5.4
 Git commit:   5604cbe
 Built:        Wed Apr 27 00:34:20 2016
 OS/Arch:      linux/amd64

Server:
 Version:      1.11.1
 API version:  1.23
 Go version:   go1.5.4
 Git commit:   5604cbe
 Built:        Wed Apr 27 00:34:20 2016
 OS/Arch:      linux/amd64

Output of docker info:

Containers: 1
 Running: 1
 Paused: 0
 Stopped: 0
Images: 21
Server Version: 1.11.1
Storage Driver: overlay
 Backing Filesystem: xfs
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: host bridge null
Kernel Version: 3.10.0-327.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.64 GiB
Name: centos-dev
ID: ACEV:LLBJ:NOYB:VEHF:V3FO:JY3A:5ETY:ETCU:WM3D:DBGZ:YF25:BUTY
Docker Root Dir: /var/lib/docker
Debug mode (client): false
Debug mode (server): false
Registry: https://index.docker.io/v1/
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled

Steps to reproduce the issue:

  1. docker run --rm -it -v config.json:/etc/config.json centos:7 bash
  2. docker run --rm -it -v ./config.json:/etc/config.json centos:7 bash
  3. docker run --rm -it -v /root/config.json:/etc/config.json centos:7 bash

Describe the results you received:

  1. I get a folder "/etc/config.json" in container, not a file
  2. docker: Error response from daemon: create ./config.json: "./config.json" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed.
  3. passed, I got a file in container

Describe the results you expected:
I expected docker run to support mount a local file using a relative path.

related issue: https://github.com/docker/docker/issues/22016

versio1.11

Most helpful comment

I am going to close this as it is working as intended and documented, even if it is a bit confusing. If you feel the documentation should be improved please submit a patch!

You can do -v $PWD/../../path:/location to use a relative path indirectly.

All 3 comments

@subchen This is pretty much stated in the documentation

The container-dest must always be an absolute path such as /src/docs. The host-src can either be an absolute path or a name value. If you supply an absolute path for the host-dir, Docker bind-mounts to the path you specify. If you supply a name, Docker creates a named volume by that name.

  1. docker see that as a name for a volume, and thus, create the volume, create a folder for it inside and mount the volume in it.
  2. docker _still_ see that as a name for a volume but / is not allowed in the name of a volume, and thus it fails
  3. working as expected :angel:

The reason why the docker cli does not take relative path is because the docker client and the docker daemon might not be on the same host. Thus how should the relative path handled ?

  • on client side ? but then, the daemon not being on the same host, might not have the file at this place, and even if it has, is the content of the file the same ?
  • on daemon side ? but relative to what path then ? path of the daemon ?

I am going to close this as it is working as intended and documented, even if it is a bit confusing. If you feel the documentation should be improved please submit a patch!

You can do -v $PWD/../../path:/location to use a relative path indirectly.

@vdemeester @justincormack thanks for your explains.

-v $PWD/../../path:/location can resolve my issue.

Was this page helpful?
0 / 5 - 0 ratings