Docker Community Forums

Share and learn in the Docker community.

File Path issue in Docker toolbox (docker-compose.yml)

docker

(Deepaksbl) #1

Hi, i setup a node project (project name :- dtest, path: c:/dtest) and run it with docker (command docker build and docker run)… it is working fine…

Now i set up another project and try to run it with docker composer (name: dctest , path c:/dctest)…
project structure is listed below

dctest
– apps
– .env
– docker.compose.yml

.env

COMPOSE_CONVERT_WINDOWS_PATHS=1

MYSQL_PORT = 3306
DTEST_PORT = 15000

DTEST = C:\dtest

docker-compose.yml

version: '2.1'
services:
    mysql:
        image: mysql
        container_name: test-mysql
        restart: always
        ports:
            - '${MYSQL_PORT:-3306}:3306'

    dtest:
        image: node:8.5-alpine
        container_name: dtest
        environment:
            - NODE_PORT=15000
        restart: always
        ports:
            - '${DTEST_PORT:-15000}:15000'
        working_dir: /apps/dtest
        volumes:
           - "${DTEST:-./apps/dtest}:/apps/dtest"
        command: ["npm", "start"]

When i tried to run it with command “docker-composer up -d” i got the error that can not mount vloume. i Tried with multiple path format but it display path related issue… like

  1. ERROR: for dtest Cannot start service dtest: oci runtime error: container_linux.go:265: starting
    container process caused “exec: “apps/dtest/entrypoint.sh”:
    stat apps/dtest/entrypoint.sh: no such file or directory”

  2. ERROR: for dtest Cannot start service dtest: oci runtime error: container_linux.go:265: starting
    container process caused “exec: “apps/dtest/package.json”:
    stat apps/dtest/package.json: no such file or directory”

  3. I change the command : [“ls”, “-lah”], and again run the up command result is listed below

drwxr-xr-x 6 root root 140 Dec 26 11:11 .
drwxr-xr-x 3 root root 4.0K Dec 27 05:33 …
drwxr-xr-x 2 root root 40 Dec 26 11:11 entrypoint.sh
-rw-r–r-- 1 root root 27 Dec 23 20:56 package-lock.json
drwxr-xr-x 2 root root 40 Dec 25 13:00 package.json
drwxr-xr-x 3 root root 60 Dec 26 11:11 scripts

But my dtest folder contains some other files and folder like (node_modules, dist, images…) and also it display entrypoint.sh and package.json as directory not a file.

Versions
Docker version 17.10.0-ce, build f4ffd25

docker-machine.exe version 0.13.0, build 9ba6da9

docker-compose version 1.16.1, build 6d1ac219
docker-py version: 2.5.1
CPython version: 2.7.13
OpenSSL version: OpenSSL 1.0.2j 26 Sep 2016

Please tell me how i can run the project using docker-compose. thanks in advance.


(Sam) #2

isnt there an extra ‘:’ in there

after substitution it would be

  • “${C:\dtest:-./apps/dtest}:/apps/dtest”

and wouldn’t a better definition be

  • “$DTEST/apps/dtest:/apps/dtest”

(Deepaksbl) #3

Thanks for your reply…
actually i tried with multiple paths like

  1. “DTEST:/apps/dtest”
  2. “‘C:/dtest’:‘apps/dtest’“
    3.”‘C:/dtest’:‘apps/dtest’:rw”
  3. “/c/dtest:apps/dest”

but volume not mount …


(Sam) #4

ok, 1st to use the windows path with the ‘:’ you MUST use the --mount,type=bind syntax, as the -v (o r–volume) syntax uses ‘:’ as the parameter parser…

the 1st parm in the -v is the volume NAME (docker create volume) or the path.
the 2nd parm is the file path location in the running container
the 3rd parm is the rw/read only , etc flags (options)…

i think you should try the --mount,type=bind,source=,dest= syntax


(Deepaksbl) #5

Hi, as per your suggestion i run the command

docker run -it \
  --name temp \
  --mount type=bind,source=C:/dtest,target=/apps/dtest \
  node:8.5-alpine sh

it return error message
C:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: invalid mount config for type “bind”: invalid mount path: ‘C:/dtest’ mount path must be absolute.
See ‘C:\Program Files\Docker Toolbox\docker.exe run --help’.

I also run the command

docker run -it \
  --name temp \
  --mount type=bind,source=/c/dtest,target=/apps/dtest \
  node:8.5-alpine sh

it successfully executed but volume not mounted…(also -v option command executed)… but when i search for the file in container then nothing is mounted. for your reference

/app # ls /
app    apps   bin    dev    etc    home   lib    media  mnt    opt    proc   root   run    sbin   srv    sys    tmp    usr    var
/app # ls /apps
dtest
/app # ls /apps/dtest/
/app #

With --mount,type=bind,source=,dest= syntax, i got the error so i replace dest with target
invalid argument “type=bind,source=C:/dest,dest=/apps/dest” for --mount: unexpected key ‘dest’ in 'dest=/
apps/dest’
See ‘docker run --help’.


(Sam) #6

so, one thing…

please provide ls -laF (or dir /s) of the host volume, (C:/dtest)

i think it is mounted as requested…

in the container you have (at least)
/apps/dest/app

/apps/dest came from the mount dest=

someone last week spent hours trying to find why a jar file was not found, and he was using the wrong name…


(Deepaksbl) #7

hi, i cross check my all the name … every thing is like as document in docker documn=entation and also i cross check my commands… i run the ls -lah command and the output is for you reference

$ docker run  -it --name temp   --mount type=bind,source=/c/dtest,target=/apps/dtest keymetrics/pm2 sh

/app # ls -lah
total 8
drwxr-xr-x    2 root     root        4.0K Dec 29 05:54 .
drwxr-xr-x   44 root     root        4.0K Dec 29 05:54 ..
/app # cd ..
/ # ls -lah
total 72
drwxr-xr-x   44 root     root        4.0K Dec 29 05:54 .
drwxr-xr-x   44 root     root        4.0K Dec 29 05:54 ..
-rwxr-xr-x    1 root     root           0 Dec 29 05:54 .dockerenv
drwxr-xr-x    2 root     root        4.0K Dec 29 05:54 app
drwxr-xr-x    3 root     root        4.0K Dec 29 05:54 apps
drwxr-xr-x    2 root     root        4.0K Dec 13 19:25 bin
drwxr-xr-x    5 root     root         360 Dec 29 05:54 dev
drwxr-xr-x   18 root     root        4.0K Dec 29 05:54 etc
drwxr-xr-x    3 root     root        4.0K Dec 13 19:07 home
drwxr-xr-x    7 root     root        4.0K Dec  1 16:31 lib
drwxr-xr-x    5 root     root        4.0K Dec  1 16:31 media
drwxr-xr-x    2 root     root        4.0K Dec  1 16:31 mnt
drwxr-xr-x    3 root     root        4.0K Dec 13 19:25 opt
dr-xr-xr-x  152 root     root           0 Dec 29 05:54 proc
drwx------    6 root     root        4.0K Dec 29 05:54 root
drwxr-xr-x    2 root     root        4.0K Dec  1 16:31 run
drwxr-xr-x    2 root     root        4.0K Dec  1 16:31 sbin
drwxr-xr-x    2 root     root        4.0K Dec  1 16:31 srv
dr-xr-xr-x   13 root     root           0 Dec 29 05:54 sys
drwxrwxrwt    3 root     root        4.0K Dec 22 11:16 tmp
drwxr-xr-x   18 root     root        4.0K Dec 22 11:16 usr
drwxr-xr-x   14 root     root        4.0K Dec  1 16:31 var
/ # cd apps/
/apps # ls -lah
total 8
drwxr-xr-x    3 root     root        4.0K Dec 29 05:54 .
drwxr-xr-x   44 root     root        4.0K Dec 29 05:54 ..
drwxr-xr-x    2 root     root          40 Dec 21 13:51 dtest
/apps # cd dtest/
/apps/dtest # ls -lah
total 4
drwxr-xr-x    2 root     root          40 Dec 21 13:51 .
drwxr-xr-x    3 root     root        4.0K Dec 29 05:54 ..

It will create the folder /apps/dtest but the files are not mounted … also /apps/dtest is the container path… so if it is not exits then it will be created…


(Sam) #8

can you show the directory list of /c/dtest (source=/c/dtest) on the host system.


(Deepaksbl) #9

i resolve my issue. thanks


(Sam) #10

great. can u tell us what you changed to make it work, in case others have the same trouble?


(Deepaksbl) #11

in docker toolbox and window by defult u can access only “C:/users//project” folder …

in my case my path is “C:/dtest” so i can not access this path.

So to access any path in host device u need to first include that path in shared folder and after that u need to mount that folder in docker-machine


(Sam) #12

thanks… i did not know that.