Reputation: 767
Is it possible to config the port number in docker under "host mode"?
I wanna bind the application to 5050 port instead of 80 port .
However, when I run below script, it will default bind in 80 port:
sudo docker run --name=myname --network host -d webapi:1.0.0 --restart=always
So I tried to run with "-p 5050", for example
sudo docker run --name=myname --network host -d webapi:1.0.0 --restart=always -p 5050
sudo docker run --name=myname --network host -d webapi:1.0.0 --restart=always -p 5050:5050
Unfortunately, my Linux terminal returned with :
WARNING: Published ports are discarded when using host network mode
The docker image looks like something like this:
And my Dockerfile looks like this:
FROM microsoft/dotnet:2.1-aspnetcore-runtime
WORKDIR /publish
COPY . .
EXPOSE 5050
ENTRYPOINT ["dotnet", "WebApi.dll"]
Upvotes: 2
Views: 5831
Reputation: 767
Thanks user "@atline" for the answer. Only 80 port is allowed. More reference is found here: https://docs.docker.com/network/host/
Upvotes: 0
Reputation: 14903
Easy way out would be to run your application on 5050
port. Once your container is up & running you must be able to access your app on port 5050 on Docker host. You need not to bind any kind of ports because you are using the host network itself.
Upvotes: 1