0

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?

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
New contributor
NKiD is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

NKiD is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.