How to change remote directory with Node.js interpreter in a Docker container

Answered

I am setting up a remote Node.js interpreter in a Docker container following these steps:

https://www.jetbrains.com/help/idea/2016.3/configuring-node-js-interpreters.html#d100000e518

However, for certain reasons, I need to mount my project directory to a different location than "/opt/project". I was able to change this, but when I run the configuration, it's still looking for the JavaScript file in "/opt/project", resulting in an error:

Error: Cannot find module '/opt/project/index.js'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:134:18)
at node.js:962:3

I can't find the setting to change this.

0
19 comments

Please can you provide screenshots of your Run configuration and Docker container settings?

0
Avatar
Permanently deleted user

Here are my settings.

Run configuration:

Docker container settings

0

Thanks! Looks normal

We will try to check it once more here, meanwhile you can additionally have a look into logs of the container (in Docker toolwindow you should be able to find this container, stopped - and see the logs).



also, in this view you can double check the volumes

0
Avatar
Permanently deleted user

Actually I don't see the container in the Docker window. It seems the container gets removed as soon as the command is over. Is there an option in IntelliJ to make it not automatically remove containers?

I tried removing the JavaScript file parameter from the Run configuration so that it just starts an idle Node interpreter and I can check the container in the Docker window, but there are no logs (since nothing ran) and the volume also looks fine.

0
Avatar
Permanently deleted user

Elena, just to clarify what I want for my setup. What I really want is to only mount a sub-directory in my project to the container.

Docker image:

-contains the /var/task/index.js file

Project:

-contains a src directory

Container:

-mount <project>/src to /var/task/src

-run /var/task/index.js

 

Thanks

0
Avatar
Permanently deleted user

Ok, I found a workaround. Instead of specifying JavaScript file, I put the full path to it in Node parameters, like so: 

Since IntelliJ is just appending this to the end of the command to call docker

1
Avatar
Permanently deleted user

I'm currently experiencing this same issue. Any updates?

0

what issue are you experiencing namely? What IDE version do you work with?

0
Avatar
Permanently deleted user

Eh I'm now thinking I was just being stubborn and refusing to mount my local directory to /opt/project (traditionally with our projects we do "/app"). Everything worked when I just mounted my local project directory to "/opt/project."

In some scenarios it may be useful to provide an option specifying the remote working directory to something other than "/opt/project" but probably not necessary.

 

(WebStorm 2017.2.4)

0

>In some scenarios it may be useful to provide an option specifying the remote working directory to something other than "/opt/project" but probably not necessary.

 

well... Normally if Auto configure checkbox is ticked in Node.js Run configuration, the IDE mounts your project as /opt/project inside the container. If this option is not enabled, you have to specify the mappings yourself in volume bindings field of Container settings, and it shouldn't necessary be /opt/project

0
Avatar
Permanently deleted user

Makes sense. Thanks for the quick responses!

0
Avatar
Permanently deleted user

Am i get it right that I can't launch from Windows into Linux remote Docker? Here's my launch configuration:

 

 

And here's my exception when running;

 

docker://3cx/selenium-video:latest/node index.js
module.js:471
throw err;
^

Error: Cannot find module '/opt/project/index.js'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:383:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:496:3

Process finished with exit code 1

0

Can you provide a screenshot of docker container settings dialog?

0
Avatar
Permanently deleted user

Here it is: 

 

0
Avatar
Permanently deleted user

Ok. But there's nothing except volume binding. You can see it in the first screenshot.

 

0

Nick,

You have Docker server running on the remote machine `selenium.3cx.test`. In your case volume bindings is not working straightforward because there is no `C:\selenoid-video` directory on this remote machine.

There is a workaround to make Docker configuration work --- you could setup SFTP Deployment using IDE (or upload files in another way) from your local machine to `selenium.3cx.test` to the directory `/c/selenoid-video` (if this Linux or OS X) and then volume bindings should work.

0
Avatar
Permanently deleted user

well... Normally if Auto configure checkbox is ticked in Node.js Run configuration, the IDE mounts your project as /opt/project inside the container. If this option is not enabled, you have to specify the mappings yourself in volume bindings field of Container settings, and it shouldn't necessary be /opt/project

This isn't working for me in 2018.  My docker containers use a working directory of /home/app/service_name, but the remote node interpreter is trying to use /opt/projects, even though I mapped the directories.  

 

Here are my container settings:

-p :3040:3000/tcp -p :5858:5858/tcp -v /Users/ericwood/dev/projects/Integrations/IntegrationAuthorizationService:/home/app/IntegrationAuthorizationService -v /Users/ericwood/dev/projects/Integrations/IntegrationAuthorizationService/node_modules:/home/app/IntegrationAuthorizationService/node_modules:ro -e NODE_PATH=/home/app/IntegrationAuthorizationService

 

2
Avatar
Permanently deleted user

Did any of you find a solution for this, i am having the same problem as Ewood, even though i mapped the directories, webstorm is autoconfiguring itself to map the project to /opt/project/ ?

0

Please sign in to leave a comment.