0

I setup Docker on MacOS yesterday, and wanted to run npm and getting: -bash: npm: command not found

What do I need to do to get it working okay? Thx.

3
  • Have you install the npm ? Commented Nov 30, 2017 at 2:26
  • What is the command you are using? Commented Nov 30, 2017 at 5:32
  • MacBook-Air:test-stable name$ npm install random-ext -bash: npm: command not found Commented Dec 1, 2017 at 2:59

1 Answer 1

1

npm isn't installed on the image you're using.

You can do either of the following:

  1. Install it via traditional means; dependent on the OS you're using.

  2. Use an image, such as the official node image which will come with it pre-installed.

You could use #2 in a way such as:

 docker run node npm -v
Sign up to request clarification or add additional context in comments.

9 Comments

@Patrick Please be sure to accept the answer if it answered your question. Cheers!
Thanks. I ran option #2 as shown: MacBook-Air:~ name$ docker run node npm -v Unable to find image 'node:latest' locally latest: Pulling from library/node 85b1f47fba49: Pull complete ... Digest: sha256:7c9099e0f68242387d7755eaa54c287e16cedd3cca423444ca773794f5f1e423 Status: Downloaded newer image for node:latest 5.5.1 But then after MacBook-Air:test-stable name$ npm install random-ext -bash: npm: command not found Why am I still getting command not found?
@Patrick - it looks like it worked! See the 5.5.1 that printed out? That's from running npm -v. When you ran npm install random-ext you're running that on your local machine, not on Docker. If you want to drop into a shell on the Docker machine, run docker run -it node /bin/sh
I saw the 5.5.1 and noticed it installed, but then npm install random-ext didn't run again and I got the same error. Is "docker run -it node /bin/sh" the same as "npm install random-ext" then? Or how do I run it to install random-ext? Thanks.
@Patrick; the last argument of that command is the command you are running in the container. In the first example; we ran npm -v and then the container exits. If you run /bin/sh as the command (With the -it flags) then you will run /bin/sh which will run the shell interpreter - and now you can interact with the system, but when you finish (crtl+c, type exit, etc.) then again - the container exits. If you want to install commands, do so within the shell; or better yet - codify it into a Dockerfile and build a new image so you can re-use it.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.