Installing npm dependencies inside docker and testing from level

I want to use Docker to create development environments for a simple node.js. project. I would like to install the project dependencies (they are all npm packages) inside the docker container (so they will not touch my host) and still mount my code using the volume. Thus, the container should be able to find the folder node_modulesin the path where I will mount the volume, but I should not see it from the host.

This is my Docker file:

FROM node:6


RUN mkdir /code
COPY package.json /code/package.json
WORKDIR /code

RUN npm install

This is how I run it:

docker build --tag my-dev-env .

docker run --rm --interactive --tty --volume $(pwd):/code my-dev-env npm test

And this is my .json package:

  {
    "private": true,
    "name": "my-project",
    "version": "0.0.0",
    "description": "My project",
    "scripts": {
      "test": "jasmine"
    },
    "devDependencies": {
      "jasmine": "2.4"
    },
    "license": "MIT"
  }

It fails because it cannot find jasmine, therefore it does not install it:

> jasmine

sh: 1: jasmine: not found

Can I do something with Docker? An alternative could be installing packages around the world. I also tried to npm install -gno avail.

Debian Docker 1.12.1, build 23cf638.

+4
2

/code/node_modules , . :

docker run --rm --interactive --tty --volume /code/node_modules --volume $(pwd):/code my-dev-env npm test

@JesusRT, npm install , - $(pwd) to /code /code . , , /code , - /code/node_modules, .

Docker-compose: node_modules npm.

+3

, /code.

, npm install , /code node_modules. , /code docker run, .

npm install npm test:

docker run --rm --interactive --tty my-dev-env npm install && npm test

, jasmine package.json :

"scripts": {
      "test": "./node_modules/.bin/jasmine"
    }
+1

Source: https://habr.com/ru/post/1652107/


All Articles