docker-node icon indicating copy to clipboard operation
docker-node copied to clipboard

node:8.15.1 cannot access https://localhost from host to container.

Open frankchen76 opened this issue 5 years ago • 14 comments

Hi,

I am trying to use node:8.15.1 version for SharePoint Framework development. I use the following Dockerfile to create my image. however, when I access https://localhost:4321/temp/workbench.html from my host laptop, I got "this site can't be reached" error from my browser. I see my container showed "Request: [::ffff:172.17.0.1] '/workbench'" and there is nothing out. Please see below for my configurations: host: windows 10 v1809 docker: Dcoker desktop for windows. v2.0.0.3. Build: 8858db3 Dockerfile:

FROM node:8.15.1

EXPOSE 5432 4321 35729

RUN npm i -g gulp yo @microsoft/generator-sharepoint @pnp/office365-cli

VOLUME /usr/app/spfx
WORKDIR /usr/app/spfx
RUN useradd --create-home --shell /bin/bash spfx && \
    usermod -aG sudo spfx && \
    chown -R spfx:spfx /usr/app/spfx

USER spfx

CMD /bin/bash

I also have problem to use NPM install to restore packages for my project and always got sass installation error.

I used node:6.11.0 for SharePoint Framework 1.4.1 and had no problem for that.

Can anyone point me out how to solve localhost request and NPM install issues?

Thanks

frankchen76 avatar Mar 24 '19 07:03 frankchen76

@frankchen76 you need to bind a host port to the container port at runtime. Are you doing docker run or are you using docker-compose?

LaurentGoderre avatar Mar 25 '19 13:03 LaurentGoderre

@LaurentGoderre thanks for your response. yes, I used docker run to start my container. the following is my docker run

docker run -it --rm --name spfx-dev --mount type=bind,source=c:/dockerprojects,destination=/usr/app/spfx -p 5432:5432 -p 4321:4321 -p 35729:35729 frank/spfx:SPFx1.8-Node8.15.0

or

docker run -it --rm --name spfx-dev -v /c/dockerprojects:/usr/app/spfx -p 5432:5432 -p 4321:4321 -p 35729:35729 frank/spfx:SPFx1.8-Node8.15.0

it was weird that I used the same docker run for a node 6.11.0 image and had no problem at all. BTW, do you have ideas why NPM install got failed somehow?

frankchen76 avatar Mar 25 '19 17:03 frankchen76

What is the output of docker ps?

LaurentGoderre avatar Mar 26 '19 15:03 LaurentGoderre

please see the screenshot below:

image

frankchen76 avatar Mar 26 '19 17:03 frankchen76

So it is bound properly. Are you sure a process is listening on those ports in the container?

LaurentGoderre avatar Mar 27 '19 12:03 LaurentGoderre

@LaurentGoderre while I am going to check if a process is listening on those port in my container, do you know what was the reason to cause NPM install failed. the following came from my npm:

2733 verbose stack Error: [email protected] install: `node scripts/install.js`
2733 verbose stack Exit status 1
2733 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
2733 verbose stack     at emitTwo (events.js:126:13)
2733 verbose stack     at EventEmitter.emit (events.js:214:7)
2733 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
2733 verbose stack     at emitTwo (events.js:126:13)
2733 verbose stack     at ChildProcess.emit (events.js:214:7)
2733 verbose stack     at maybeClose (internal/child_process.js:915:16)
2733 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
2734 verbose pkgid [email protected]
2735 verbose cwd /usr/app/spfx/spfx2
2736 verbose Linux 4.9.125-linuxkit
2737 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "[email protected]" "--unsafe-perm=true" "--allow-root"
2738 verbose node v8.15.0
2739 verbose npm  v6.4.1
2740 error code ELIFECYCLE
2741 error errno 1
2742 error [email protected] install: `node scripts/install.js`
2742 error Exit status 1
2743 error Failed at the [email protected] install script.
2743 error This is probably not a problem with npm. There is likely additional logging output above.
2744 verbose exit [ 1, true ]

if I install it from node without using docker, it was fine. There are a few articles to mention this was caused by node.js for mount volume. do you have ideas about that? Thanks

frankchen76 avatar Mar 27 '19 21:03 frankchen76

My first guess for a culprit would be using npm install using the root user instead of node user. If you add -u node to your command, do you get the same error?

LaurentGoderre avatar Mar 28 '19 13:03 LaurentGoderre

I just tried what you suggested as the following. But unfortunately, I still got same error message.

docker run -it --rm --name spfx-dev -v /c/dockerprojects:/usr/app/spfx -p 5432:5432 -p 4321:4321 -p 35729:35729 -u node frank/spfx:SPFx1.8-Node8.15.0

error: npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: node scripts/install.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-03-28T16_57_46_805Z-debug.log

frankchen76 avatar Mar 28 '19 17:03 frankchen76

I'm having the similar issue. Built the image with no problem and got the container running no problem. The port mapping is correct. Just couldn't access the node app from localhost on my host browser.

yuanzhou avatar Sep 18 '19 19:09 yuanzhou

So it tuned out that I had to use 0.0.0.0 instead of localhost in the hapi app.

yuanzhou avatar Sep 23 '19 16:09 yuanzhou

Hi there, I'm facing the same issue. Trying docker for the first time.

docker run -p 80:3000 [my_node_app_image] in my dockerfile : EXPOSE 3000 Server runs on container and listens to port 3000 (as per my console.log msg) but no response when I request localhost or even 0.0.0.0

The app works fine locally, no response when running on docker container.

Any ideas? How can I further investigate the issue? Where should I look? Many thanks

Container running, see ports mapping (docker ps): image

Node app running: image

abenziada avatar Nov 12 '19 21:11 abenziada

Alright, never mind guys. Used the container's ip address. Got my response. docker-machine ip

Have a nice day ::)

abenziada avatar Nov 12 '19 21:11 abenziada

I had similar issue, I'm on Windows, and have Kaspersky internet security which caused this issue by some firewalls rules. Just check your firewall, sometimes it causes problems with mounting your directories or mapping the ports.

mazux avatar Jan 12 '20 00:01 mazux

try to use docker machine ip and the port number whichever you have provided. for getting docker machine ip, use docker-machine ip suppose you got 192.168.99.100 then after colon write port such as : 1880 finally as http://192.168.99.100:1880/

ravi2695 avatar Feb 12 '20 07:02 ravi2695