docker-archive/toolbox

Volumes issues with Docker Toolbox on Windows 10

sangxxh opened this issue · 4 comments

I'm using Docker Toolbox on Windows 10 and have enabled Shared Folders settings with the correct custom paths in VirtualBox where the project is located:

VirtualBox Mount VOlume

I have set up Dockerfile and docker-compose.yml to test run a simple Node.js server. The service-test make use of volumes so that later I can config the project with nodemon for live update when coding the project.

But Docker Compose fails to run on Windows (see logs at the bottom)

What I have tried:

  • I run the same project on a Ubuntu computer and it works
  • On Windows, docker-compose run works fine if I remove the volumes entries in docker-compose.yml
  • Set COMPOSE_CONVERT_WINDOWS_PATHS to 1 in the terminal

So there must be an issue where the container has failed to see the files in the volume on the host computer on Windows machine.

Currently, I have to run the project inside a Ubuntu virtual machine.
How do I get this to work on Windows?

Note that both docker and docker-compose have this issue with volume.

Code

service-test/Dockerfile:

FROM node:13.1.0

ARG NODE_ENV=development
ENV NODE_ENV $NODE_ENV

RUN npm i npm@latest -g

WORKDIR /usr/app
COPY package*.json ./
RUN npm install
COPY . .

CMD [ "npm", "start" ]

docker-compose.yml

version: "3"

services:
  service-test:
    build:
      context: ./service-test
      dockerfile: Dockerfile
    ports:
      - "8080:8080"
    volumes:
      - ./service-test:/usr/app
      - /usr/app/node_modules

service-test/index.js

var http = require('http');

//create a server object:
console.log('creating server');

http.createServer(function (req, res) {
  res.write('Hello World!'); //write a response to the client
  res.end(); //end the response
}).listen(8080); //the server object listens on port 8080

service-test/package.json

{
  "name": "service-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

Log & Error

$ docker-compose up --build 

Creating network "test_default" with the default driver
Building service-test
Step 1/9 : FROM node:13.1.0
 ---> 1a77bcb355eb
Step 2/9 : ARG NODE_ENV=development
 ---> Using cache
 ---> 0596027234a6
Step 3/9 : ENV NODE_ENV $NODE_ENV
 ---> Using cache
 ---> 3380c6658fd4
Step 4/9 : RUN npm i npm@latest -g
 ---> Using cache
 ---> 5ca166a7624d
Step 5/9 : WORKDIR /usr/app
 ---> Using cache
 ---> 1f0dae78d9b8
Step 6/9 : COPY package*.json ./
 ---> ba427c0edca7
Step 7/9 : RUN npm install
 ---> Running in 3bd6e19bfb6c

6 packages are looking for funding.
Run "npm fund" to find out more.
Removing intermediate container 3bd6e19bfb6c
 ---> d12b4cd57388
Step 8/9 : COPY . .
 ---> c9377f559808
Step 9/9 : CMD [ "npm", "run", "watch" ]
 ---> Running in 669743e4dfb0
Removing intermediate container 669743e4dfb0
 ---> 3e92c8b595c4
Successfully built 3e92c8b595c4
Successfully tagged test_service-test:latest
Creating test_service-test_1 ... done                                                                                                                                                                                                 Attaching to test_service-test_1
service-test_1  | npm ERR! code ENOENT
service-test_1  | npm ERR! syscall open
service-test_1  | npm ERR! path /usr/app/package.json
service-test_1  | npm ERR! errno -2
service-test_1  | npm ERR! enoent ENOENT: no such file or directory, open '/usr/app/package.json'
service-test_1  | npm ERR! enoent This is related to npm not being able to find a file.
service-test_1  | npm ERR! enoent
service-test_1  |
service-test_1  | npm ERR! A complete log of this run can be found in:
service-test_1  | npm ERR!     /root/.npm/_logs/2019-11-24T11_48_06_131Z-debug.log
test_service-test_1 exited with code 254

Hi,

which version of docker-toolbox are you using?

TL;DR

Ensure that the docker-machine that you created or that was created for you is using a version of VirtualBox Guest Additions that matches yours VirtualBox version (you can find these versions in the release notes of docker-toolbox and boot2docker version which was used in docker-machine creation)

Long Version

I had a similar issue on docker-toolbox for Mac with docker-toolbox 19.03.1: I was unable to share any volume between host and containers and I found that VirtualBox Shared Folders between my Mac and the docker-machine was not working (when creating the docker-machine with VirtualBox, it shares by default the Mac /Users folder, and that mount cannot be found inside the docker-machine)

I then found the cause: I created the docker-machine using boot2docker 19.03.1 (I tipically use the version that matches docker-toolbox version) which was shipped with VirtualBox Guest Additions 6.0.10, while docker-toolbox 19.03.1 ships with VirtualBox 5.2.x.
Manually upgrading VirtualBox to 6.0.10 fixed the issue for me.

@sgradix My scenario exactly matched with yours but still not able to resolve this volume issues...
-step1. downloaded the docker toolbox from https://github.com/docker/toolbox/releases (19.03.1)
-step2. update the oracle vm to latest 6 version (i.e. 6.0.20)
Are there further things to consider?

Hey!! @hantatsang have you found the solution of this problem. I am also facing the same issue while using the docker volumes.

Hey!! @hantatsang have you found the solution of this problem. I am also facing the same issue while using the docker volumes.

I ended up not using Docker Toolbox 'cause I couldn't get it to work. I just use the standard Docker Desktop app instead.