A
A
Artem00712020-01-25 20:21:46
Node.js
Artem0071, 2020-01-25 20:21:46

Is it possible to run npm locally through Docker?

I’m just trying to figure out the docker, please don’t swear too much
There is a project, it has a package.json file
I’m trying to install everything that is there not using npm locally, but somehow through docker
I write the command: docker run node npm install
In response, an error:

npm WARN saveError ENOENT: no such file or directory, open '/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/package.json'
npm WARN !invalid#2 No description
npm WARN !invalid#2 No repository field.
npm WARN !invalid#2 No README data
npm WARN !invalid#2 No license field.

Although the current directory has this file
. What's wrong here?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sokolov, 2020-01-25
@Artem0071

I will assume that the project and it package.jsonare on the host in the current folder.
Then the command:
More:

docker run                  \
  -it                       \  // интерактивно и с терминалом
  --rm                      \  // удалить контейнер после выхода
  -v "$PWD":/usr/src/app    \  // текущую папку на хосте смонтировать в контейнер
  -w /usr/src/app           \  // в конт. сделать текущей папкой смонтированную
  node                      \  // образ с nodejs
  npm install                  // команда

A
Arman, 2020-01-25
@Arik

you need to mount the folder on the fly and it is advisable to delete the container behind you, since you want to directly run the image every time
my .bash_profile

function docker-npm() {
    docker run -it --rm -v app-sync:/var/www/sites:nocopy -w=$(pwd) node npm "[email protected]"
}

// -v app-sync:/var/www/sites:nocopy на свое правим

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question