Error running Docker node container on Windows 10 - node.js

I am new to Docker and attempting to run through a few simple examples on both my Windows 10 PC and my Mac simulteneously. The example below works fine on Mac but not on the PC.
Docker Toolbox is installed and I've downloaded the official Node image from DockerHub. I used Express to create a simple Javascript-based site using Handlebars that works fine if I execute npm start locally from the host.
When I attempt to start the container with the following command I get an error on the Windows machine:
$ docker run -p 8080:3000 -v $(pwd):/var/www -w "/var/www" node npm start
npm info it worked if it ends with ok
npm info using npm#3.10.9
npm info using node#v7.2.0
npm ERR! Linux 4.4.27-boot2docker
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v7.2.0
npm ERR! npm v3.10.9
npm ERR! path /var/www/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/var/www/package.json'
npm ERR! enoent ENOENT: no such file or directory, open '/var/www/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR! /var/www/npm-debug.log
The same command works fine on the Mac and I can hit http://host-ip:8080 no problem.
Again, this is a simple example that should work on both platforms, wondering if the error may be a known difference in the way Docker Toolbox works on each platform, or perhaps a syntax error in the command.
Any help is appreciated.

With Docker Toolbox on Windows (involving VirtualBox), make sure your $(pwd) is a path starting with C:\Users\<myLogin>: only this folder is pre-shared and auto-mounted by VirtualBox.
You can try a docker run with a ls /var/www as CMD to check if /var/www does reflect your $(pwd) content.
docker run -p 8080:3000 -v $(pwd):/var/www -w "/var/www" node ls

Related

in laravel homstead project npm install get error

My operating system is windows 10. I'm using laravel homestead (ubuntu 18.04) resent release and working in a virtual box with vagrant. After installing Laravel when I try to run:
composer require laravel/breeze --dev
to get the Authenticate part it works fine. after that, it says to run npm install && npm run dev
Then I CD to my test.com project and ran that command
after install, some features below error appears.
(I get the same issue when I try to require jetstream )
I used my Git bash shell as admin. I did re-run npm, npm clear cash force, remove package.json but still having the same problem.
sudo npm install says some permission problem in the host computer.
Actually, I'm Stuck. Please help
npm ERR! code ENOENT<br>
npm ERR! syscall open<br>
npm ERR! path /home/vagrant/code/test.com/node_modules/yargs/node_modules/yargs-parser/
package.json.1050278784
npm ERR! errno -2<br>
npm ERR! enoent ENOENT: no such file or directory, open '/home/vagrant/code/test.com/no
de_modules/yargs/node_modules/yargs-parser/package.json.1050278784'<br>
npm ERR! enoent This is related to npm not being able to find a file.<br>
npm ERR! enoent<br>
npm ERR! A complete log of this run can be found in:<br>
npm ERR! /home/vagrant/.npm/_logs/2020-12-20T04_04_37_652Z-debug.log<br>
vagrant#homestead:~/code/test.com$ cd /

How can I install nodejs manually in Linux from terminal

I have downloaded Nodejs in my Linux VM from nodejs.org, I want to install it from terminal. VM have already installed node v0.12.18 manually by someone else, I don't know how to do that. As I am installing nodejs offline, I should not depend on that whether or not npm installed.
I have tried [location]~ npm install node-v15.6.0-linux-x64.tar.gz
Getting below error
[host#machinename ~]$ sudo npm install node-v15.6.0-linux-x64.tar.gz
npm WARN excluding symbolic link bin/npm -> ../lib/node_modules/npm/bin/npm-cli. js
npm WARN excluding symbolic link bin/npx -> ../lib/node_modules/npm/bin/npx-cli. js
npm ERR! addLocal Could not install /home/usermachinename/node-v15.6.0-linux-x64.tar.g z
npm ERR! Linux 3.10.0-1062.9.1.el7.x86_64
npm ERR! argv "/usr/local/lib/nodejs/node-v0.12.18-linux-x64/bin/node" "/usr/loc al/lib/nodejs/node-v0.12.18-linux-x64/bin/npm" "install" "node-v15.6.0-linux-x64 .tar.gz"
npm ERR! node v0.12.18
npm ERR! npm v2.15.11
npm ERR! path /tmp/npm-1637-a9cb4311/unpack-5a7f411732fb/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! enoent ENOENT, open '/tmp/npm-1637-a9cb4311/unpack-5a7f411732fb/package .json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR! /home/usermachinename/npm-debug.log
How can I fix this?
You can't install the file using npm install, but since you already have the compressed file for node, my answer will hopefully help you achieve your goal.
First of all you will have to extract the tar.gz file you have node-v15.6.0-linux-x64.tar.gz, to do so just navigate to the folder where the file placed in then do the below command.
tar xf node-v15.6.0-linux-x64.tar.gz
Since you're using Linux the below command will add the new extracted node to your path.
nano ~/.profile
Add the following lines to the end:
# NodeJS
export NODEJS_HOME=/{path_to_the_extracted_folder}/node-v15.6.0-linux-x64/bin
export PATH=$NODEJS_HOME:$PATH
Please make sure you change {path_to_the_extracted_folder} to the path where you extracted the compressed file in the previous step.
Finally you can click CTRL+C to exit nano, type y then click enter.
To refresh the profile file enter the below code
. ~/.profile
Finally
To make sure everything is working fine check the nodeJs version by entering this command node -v it has to print v15.6.0.
You will not have to worry about the previously installed node version since above steps will change the nodeJs path.

Is it possible to mount host machine folder when run process in docker container on the remote machine

I'm trying to launch my cypress tests on a remote machine with docker. So from host I do:
docker -H ssh://me#host run -v /home/jenkins/agent/workspace/TEST:/e2e -w /e2e --entrypoint=npm cypress/included:5.2.0 run test
The container on remote machine starting well, but then I get such errors:
npm ERR! syscall open
npm ERR! path /e2e/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/e2e/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
The folder from host wasn't mounted into container on remote machine.
Could you please advise, is it possible to mount in such configuration? And if so - how to do that correctly?
Thanks!

lerna bootstrap fails with "no such file or directory"

Trying to run the command
lerna bootstrap --hoist
On an application I cloned from GitHub. The instructions are to
Clone
Then run lerna bootstrap --hoist
However, when running the lerna bootstrap --hoist command, each time it fails and I get an error exactly like this but the node module changes each time:
npm ERR! code ENOENT
npm ERR! syscall rename
npm ERR! path /data/packages/nodes-base/node_modules/arr-filter
npm ERR! dest /data/packages/nodes-base/node_modules/.arr-filter.DELETE
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, rename '/data/packages/nodes-base/node_modules/arr-filter' -> '/data/packages/nodes-base/node_modules/.arr-filter.DELETE'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
I am doing this on a Docker linux container. My frustration lies in the fact that the same setup worked on my previous laptop, but doesn't on this new one I have. My colleague tried this on his Ubuntu machine and it works with no issues.
I don't know the reason, but what allowed it to work was switching to the WSL mode on Docker, instead of having it use Hyper-V.

Can't run sample express app in node container on Windows

I'm watching a Docker course from Pluralsight and I need to run a Docker source on a Docker container I just downloaded.
Even though I have package.json file in the current path, it is not recognized.
Usuario#RE MINGW64 /d/node/ExpressSite
$ docker run -p 8080:3000 -v /$(pwd):/var/www -w "/var/www" node:4.4.5 npm start
npm info it worked if it ends with ok
npm info using npm#2.15.5
npm info using node#v4.4.5
npm ERR! Linux 4.4.12-boot2docker
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v4.4.5
npm ERR! npm v2.15.5
npm ERR! path /var/www/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/var/www/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR! /var/www/npm-debug.log
Why the Pluralsight does the same and it works? What's wrong with my version?
From official docs https://docs.docker.com/engine/userguide/containers/dockervolumes/:
If you are using Docker Machine on Mac or Windows, your Engine daemon has only limited access to your OS X or Windows filesystem. Docker Machine tries to auto-share your /Users (OS X) or C:\Users (Windows) directory. So, you can mount files or directories on OS X using.
docker run -v /Users/<path>:/<container path> ...
On Windows, mount directories using:
docker run -v /c/Users/<path>:/<container path> ...
So, you can create a directory inside C:\Users\<your_username> (code for example) with your code and mount it inside the container like so:
docker run -p 8080:3000 -v /c/Users/<your_username>/code:/var/www -w "/var/www" node:4.4.5 npm start
Please note that your code will be available inside the container in /var/www/ directory
pwd returns /c/Users/<my_username>. Try it yourself in Docker terminal.
You can use pwd for convenience sake:
docker run -p 8080:3000 -v $(pwd)/code:/var/www -w "/var/www" node:4.4.5 npm start
Good luck with the course and Dockerize all the things!

Resources