Reputation: 1339
I'm trying to run a simple Node.js/Express web app in a Docker (17.06) container on OS X (latest update 10.12.5). I'm unable to connect to the app at localhost:3000
and am unable to figure out what's wrong. I have also tried to connect to the VM's IP address found by running ip addr | grep global
in its console to no avail.
My app is actually just the framework JetBrains Webstorm creates when creating a new project of type 'Node.js Express App'. Note that I'm able to run this app on my host system via npm start
and successfully connect to it at localhost:3000
.
I then built a Docker image like so:
docker build -t joonas/meancopy .
Run it:
docker run -it -v `pwd`:/home/dev/src --name meancopy joonas/meancopy -p 3000:3000
And after being thrown in the VM's shell, I run npm start
and get the following:
[dev@c24d24f58f1d:~/src$ npm start
npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
npm info lifecycle [email protected]~prestart: [email protected]
npm info lifecycle [email protected]~start: [email protected]
> [email protected] start /home/dev/src
> node ./bin/www
The output is the same as when run on the host expect for the "npm info" lines in the beginning. However, I'm unable to connect to this server at localhost:3000
.
I've also tried running the image with --expose=3000
and --net="host"
because I found those when searching for solutions online, but they don't help (and to my understanding shouldn't even be necessary here).
Any help or debugging ideas are greatly appreciated!
Upvotes: 0
Views: 51
Reputation: 72858
your docker run
command is bad
docker run -it -v `pwd`:/home/dev/src --name meancopy joonas/meancopy -p 3000:3000
the way you have this written, the container is going to try and execute -p 3000:3000
as the container's process instance. you need to put the -p
parameter before the the name of the image.
docker run -it -v `pwd`:/home/dev/src --name meancopy -p 3000:3000 joonas/meancopy
Now docker will run the command defined in your Dockerfile - which will probably be the node.js app, as expected.
Upvotes: 1