I have made these failing attempts are on the OpenShift gear via SSH.
Attempt-1:
node-debug app.js
Node Inspector v0.12.7
Cannot start the server at 127.0.0.1:8080. Error: listen EACCES.
Attempt-2:
node-inspector
Node Inspector v0.12.7
Cannot start the server at 0.0.0.0:8080. Error: listen EACCES.
Attempt-3:
node --debug app.js
debugger listening on port 5858
Failed to open socket on port 5858, waiting 1000 ms before retrying
I don't know what the correct method is to get an installed node-inspector running in an OpenShift Node.JS Gear.
Not sure if this is way too late or if you have found a solution.
I've managed to get this working in OpenShift 'origin' on my local machine
I made use of the node4-rhel7 image so the following is specific (i.e entrypoint and adding to /usr/bin in the image), so change it accordingly
Here are the steps :-
create or update a Dockerfile that gave me the correct permissions (rw) for my node app
install node-inspector (npm install node-inspector --save)
add this script (call it start.sh - in a folder root/usr/bin) also remember to set execute permissions
if [ $# gt 0 ] && [ "$1" == "debug"]
then
# assume default debug port of 5858
node --debug name-of-startup.js
node_modules/node-inspector/bin/inspector.js -p 9000 --save-live-edit=true
else
node name-of-startup.js
fi
add a script called container-entrypoint also in a folder root/usr/bin
#!/bin/bash
exec "$#"
add this to your Dockerfile
ADD root /
ENTRYPOINT ["container-entrypoint"]
CMD ["start.sh"]
docker build -t name-of-your-image:version .
oc edit dc/name-of-your-node-pod
add port: 9000 and protocol: TCP in "spec.containers.ports"
add "command": [ "start.sh","debug"] in "spec.containers"
update the image to the newly built one on your local docker (name-of-your-image:version)
save (this will re-deploy your app) and execute 'oc get ep' (to get the endpoint of you app)
open chrome with with url http://your-app-endpoint:9000/?port=5858
you can now debug/set breakpoints etc and change code via the chrome interface - primitive but works like a charm :)
Related
Github link
I'm trying to debug my backend node server running inside a docker container. For the life of me I can't seem to remote debug the node process when it's running in docker. I used netstat -an to verify that ports 9229 are open in both my host machine and in the container, and I made sure to map the port 9229 on my host machine to 9229 in the container. I'm running node with nodemon --inspect --trace-warnings --unhandled-rejections=strict server.js but have also tried node --inspect server.js without success.
I've tried multiple vscode launch.json configurations, none of which have worked.
The first config is the default one and does not attempt to attach to a running node process.
The second fails with the error ENOENT: no such file or directory, open '~/Desktop/fiction-forge/package.json'. I don't know why the docker extension is looking for package.json in ~/Desktop/fiction-forge.
The third seems to try to connect, giving a loading animation in vscode, but ultimately fails. I've also tried the remote debugger in Chrome to no avail.
I am able to remote debug the node process with the chrome remote debugger when I run it on my host machine on port 9229. It remains a mystery to me why, if the ports are opened and mapped correctly, there is a difference when node is running in the container.
You can create the image and run the container with docker build -t fiction-forge . && docker run -p 3000:3000 -p 5000:5000 -p 9229:9229 fiction-forge. Then start the server with docker exec <container-name> npm run dev --prefix server.
Running node with --inspect=0.0.0.0:9229 and specifying 127.0.0.1:9229 as a connection in the chrome devtools worked.
I have searched around without much luck, or maybe because I'm too noob, but I this project online on github, https://github.com/bradtraversy/react_express_starter, and I have tried to make it so it can run with docker, but it doesn't seem like it don't want to work, in the docker terminal it says that the server is started and the react app at localhost:3000 but nothing shows up when I paste it into the browser, not even the server and api is accessable, so I figured it has to be something with the docker file.I place the dockerfile in the project folder.
My dockerfile says
FROM node:latest
WORKDIR /app
COPY package.json ./
RUN npm install
CMD npm run client-install
COPY . .
EXPOSE 3000
CMD npm run dev
and I build it by "docker build -t project ." and then run it with "docker run -p 5000:5000 project"
thank you in advance
screenshot of whats happening
EDIT: OK, I have made the server working, it turns out that docker machine has another ip than localhost, so port 5000 work as well as api call, but the react part doesn't show up on port 3000?
It looks like you're mising EXPOSE as apart of your dockerfile. This can be done right before
CMD npm run dev
like so
EXPOSE 3000
The internal port is 3000 - you need to make that available externally (on the host machine). Move EXPOSE 3000 before the CMD, then docker run -p 5000:3000 project should make your docker container available as localhost:5000/.
I have a NodeJS/Vue app that I can run fine until I try to put it in a Docker container. I am using project structure like:
When I do npm run dev I get the output:
listmymeds#1.0.0 dev /Users/.../projects/myproject
webpack-dev-server --inline --progress --config build/webpack.dev.conf.js
and then it builds many modules before giving me the message:
DONE Compiled successfully in 8119ms
I Your application is running here: http://localhost:8080
then I am able to connect via browser at localhost:8080
Here is my Dockerfile:
FROM node:9.11.2-alpine
RUN mkdir -p /app
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
CMD npm run dev
EXPOSE 8080
I then create a docker image with docker build -t myproject . and see the image listed via docker images
I then run docker run -p 8080:8080 myproject and get a message that my application is running here: localhost:8080
However, when I either use a browser or Postman to GET localhost:8080 there is no response.
Also, when I run the container from the command line, it appears to lock up so I have to close the terminal. Not sure if that is related or not though...
UPDATE:
I trying following the Docker logs such as
docker logs --follow
and there is nothing other than the last line that my application is running on localhost:8080
This would seem to indicate that my http requests are never making into my container right?
I also tried the suggestion to
CMD node_modules/.bin/webpack-dev-server --host 0.0.0.0
but that failed to even start.
It occurred to me that perhaps there is a Docker network issue, perhaps resulting in an earlier attempt at kong api learning. So I run docker network ls and see
NETWORK ID NAME DRIVER SCOPE
1f11e97987db bridge bridge local
73e3a7ce36eb host host local
423ab7feaa3c none null local
I have been unable to stop, disconnect or remove any of these networks. I think the 'bridge' might be one Kong created, but it won't let me whack it. There are no other containers running, and I have deleted all images other than the one I am using here.
Answer
It turns out that I had this in my config/index.js:
module.exports = {
dev: {
// Various Dev Server settings
host: 'localhost',
port: 8080,
Per Joachim Schirrmacher excellent help, I changed host from localhost to 0.0.0.0 and that allowed the container to receive the requests from the host.
With a plain vanilla express.js setup this works as expected. So, it must have something to do with your Vue application.
Try the following steps to find the source of the problem:
Check if the container is started or if it exits immediately (docker ps)
If the container runs, check if the port mapping is set up correctly. It needs to be 0.0.0.0:8080->8080/tcp
Check the logs of the container (docker logs <container_name>)
Connect to the container (docker exec -it <container_name> sh) and check if node_modules exists and contains all
EDIT
Seeing your last change of your question, I recommend starting the container with the -dit options: docker run -dit -p 8080:8080 myproject to make it go to the background, so that you don't need to hard-stop it by closing the terminal.
Make sure that only one container of your image runs by inspecting docker ps.
EDIT2
After discussing the problem in chat, we found that in the Vue.js configuration there was a restriction to 'localhost'. After changing it to '0.0.0.0', connections from the container's host system are accepted as well.
With Docker version 18.03 and above it is also possible to set the host to 'host.docker.internal' to prevent connections other than from the host system.
Refer to https://github.com/openfin/process-manager
Based on the README.md, I have done the following steps:
npm install
node server
I am able to see the following message from terminal(windows 7)
$ node server
Express server listening on port 5040
How do I launch the application?
I have tried to point to the localhost:5040 through chrome browser and ONLY see three tabs 'Processes', 'Cache', 'Logs' without any information.
How can I fix the issues?
npm i -g openfin-cli
openfin -l -c http://localhost:5040/app_local.json
The server script is running a local express server that hosts an OpenFin enriched web app so all you need to do it launch it on OpenFin, which in the case above we are doing with the CLI.
You can also use a node module to launch i.e. here
I'm pretty new to Docker, so I'm trying to take a node web app that I've written and Docker-ize it. The app is open source, so you can find it and the Dockerfile here: Paw-Wars
So you don't have to click through, the Dockerfile is here:
FROM mhart/alpine-node
WORKDIR /src
ADD . .
RUN npm install
EXPOSE 5050
COPY config.json /src/config.json
CMD npm run docker
So I open up the Docker Quickstart Terminal (I'm on Mac OS X), go to my path, and build it:
docker build -t paw-wars .
After it builds, I run it:
docker run paw-wars
And it spins up just fine and says it's listening on port 5050. I get the ip from docker-machine ip default, and try to connect to it on port 5050, but I get connection refused. Most searches I've done trying to solve this tell me that I need to make sure to use the correct IP, but I'm almost positive I'm doing that. Not really sure what I'm doing wrong. It's not in the repo, but I've also tried binding to 0.0.0.0 in my app (index.js), but that didn't work either.
Thanks!
The issue is that you MUST specify a port in your docker run command. I thought that using EXPOSE in your dockerfile is sufficient, but it's not. That's just to get the port exposed internally.
docker run -p 5050:5050 paw-wars worked great.