1

I launch docker container:

docker run --name node-arasaac -p 3000:3000 juanda/arasaac

And my node.js app works ok.

If I want to change host port:

docker run --name node-arasaac -p 8080:3000 juanda/arasaac

Web page is not loaded, logs from browser console:

Failed to load resource: net::ERR_CONNECTION_REFUSED
http://localhost:3000/app.318b21e9156114a4d93f.js Failed to load resource: net::ERR_CONNECTION_REFUSED

Do I need to have the same port both in host and container? It seems it knows how to resolve http://localhost:8080 so it loads my website, but internal links in the webpage go to port 3000 and it's not as good :-(

4
  • Not sure exactly what you are asking but no you don't need the host and container to have the same port. If you internal links access your nodejs app on port 3000, they can continue to do so if you run them in containers on a docker network. Is that what you mean? Commented Feb 16, 2016 at 22:48
  • When I change the port, web internal links (that always go to localhost:3000) doesn't work. docker network? Do i need some extra conf that I don't know? I thought it was provided out of the box... Commented Feb 16, 2016 at 22:53
  • When my browser try to load assets in localhost:3000 it can't because It try to do so in the localhost machine, not in the container. I mean it is forwareding requests from 8080 to 3000, but when the request is from 3000 it stays in the host. Commented Feb 16, 2016 at 22:57
  • Not sure if your use case will accommodate but typically you would want to use relative pathing for your assets and not specify a specific port like that. But again not sure you use case. Commented Feb 16, 2016 at 23:02

1 Answer 1

2

When you are running your node.js app in a docker container it will only expose the ports externally that you designate with your -p (lowercase) command. The first instance with, "-p 3000:3000", maps the host port 3000 to port 3000 being exposed from within your docker container. This provides a 1 to 1 mapping, so any client that is trying to connect to your node.js service can do so through the HOST port of 3000.

When you do "-p 8080:3000", docker maps the host port of 8080 to the node.js container port of 3000. This means any client making calls to your node.js app through the host (meaning not within the same container as your node.js app or not from a linked or networked docker container) will have to do so through the HOST port of 8080.

So if you have external services that expect to access your node.js at port 3000 they won't be able.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.