Reputation: 1731
I am following this tutorial to set up docker
for my node.js rest api and there is this line in the tutorial:
docker run -p 49160:8080 -d <your username>/node-web-app
And this description:
The -p flag redirects a public port to a private port inside the container. Run the image you previously built:
From the description, I know that port 49160 is a public port and 8080 is a private port. Since I am exposing port 5001 in my nodejs app, so I think I am running:
docker run -p 49160:5001 -d <your username>/node-web-app
But what exactly is a public port? Why is it "49160"?
Upvotes: 4
Views: 2214
Reputation: 9584
In your example port 8080 leads to some server (probably web server / Node) located inside of your Docker container. The outside (the host you're working on) port is 49160
. The Docker setting named -p
connects the inner port 8080
to the outer port 49160
. If you now open the browser in your host system and hit the url http://localhost:49160
you will essentially access port 8080
inside the container.
Port 8080
is usually used for web servers. It is not obligatory though.
Port 49160
is just some port you or the auther of the tutorial decided to take as an example.
If you have a server inside the container listening on port 5001
it will not be accessible in your setup. If you want to make it accessible, you could adapt the following command:
docker run -p 49160:8080 -p 49159:5001 -d <your username>/node-web-app
Upvotes: 2
Reputation: 11223
It can be anything. Tutorial just used a random port. You can change it whatever you want. Then you can access your node-web-app running inside container at port 5001 at localhost:49160 from your host machine.
Upvotes: 3