40

Ive been given a docker container which is run via a bash script. The container should set up a php web app, it then goes on to call other scripts and containers. It seems to work fine for others, but for me its throwing an error.

This is the code

sudo docker run -d \
   --name eluci \
   -v ./config/eluci.settings:/mnt/eluci.settings \
   -v ./config/elucid.log4j.settings.xml:/mnt/eluci.log4j.settings.xml \
   --link eluci-database:eluci-database \
   /opt/eluci/run_eluci.sh

This is the error

docker: Error response from daemon: create ./config/eluci.settings: 
"./config/eluci.settings" includes invalid characters for a local
volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to 
pass a host directory, use absolute path.

Im running docker on a centos VM using virtualbox on a windows 7 host.

From googling it seems to be something to do with the mount, however I dont want to change it in case the setting it breaks or is relied upon in another docker container. I still have a few more bash scripts to run, which should orchestrate the rest of the build process. As a complete newb to Docker, this has got me stumped.

xpt
  • 20,363
  • 37
  • 127
  • 216
Paul M
  • 3,937
  • 9
  • 45
  • 53
  • 1
    Have you tried adding " " around the path? Such as: "./config/eluci.settings:/mnt/eluci.settings" – Sergiu Oct 02 '17 at 13:23
  • 1
    good spot, but that didn't work either :-( – Paul M Oct 03 '17 at 11:14
  • Possible duplicate of [Mount current directory as a volume in Docker on Windows 10](https://stackoverflow.com/questions/41485217/mount-current-directory-as-a-volume-in-docker-on-windows-10) – kenorb Mar 11 '19 at 22:16

1 Answers1

80

The command docker run -v /path/to/dir does not accept relative paths, you should provide an absolute path. The command can be re-written as:

sudo docker run -d \
   --name eluci \
   -v "/$(pwd)/config/eluci.settings:/mnt/eluci.settings" \
   -v "/$(pwd)/config/elucid.log4j.settings.xml:/mnt/eluci.log4j.settings.xml" \
   --link eluci-database:eluci-database \
   /opt/eluci/run_eluci.sh
Francesco Borzi
  • 56,083
  • 47
  • 179
  • 252
Ayushya
  • 9,599
  • 6
  • 41
  • 57
  • 1
    dollar needs to be inside braces, and a forward slash before it -v "/($pwd)/config/eluci. – Paul M Oct 03 '17 at 13:33
  • I agree and accept what you are saying, I just want to confirm if what I have been using on my system, also works on other systems, or using ` "/($pwd)` is a better thing. – Ayushya Oct 03 '17 at 14:12
  • 2
    I've just done this, and I have to refute @PaulM's comment, at least on Linux (Ubuntu 20.04). ($pwd) did not work, $(pwd) did work – Simon Jan 02 '21 at 14:10
  • 1
    Yep not sure where that's supposed to work. `($pwd)` inserts the value of a variable called `$pwd`; `$(pwd)` insert the result of running the `pwd` _command_ in a sub-shell. The latter is almost certainly what's intended here. – boycy Jul 07 '21 at 10:23
  • 1
    My $pwd was stored as $PWD - make sure to match the capitalization (`echo $pwd; echo $PWD` or `printenv`) – Walker Sutton Sep 23 '21 at 19:03