Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Dot net application when run locally it launches on url http://localhost:59901, and I am trying to dockerize this application. below is the docker file, I have pulled all the dependent images before these line in docker file.

ENV DOTNET_URLS=http://+:80
COPY bin/Release/netcoreapp2.1/publish/ /opt/Pcit/common
WORKDIR /opt/Pcit/common
ENTRYPOINT ["./pcit/common"]
EXPOSE 8080


have build the docker Image using this command
Docker build -t common:v1 .


and below command to run container
Docker run -p 8080:8080 imageid


in the Docker desktop I see the container is listening to http://localhost/5000, which I have not declared anywhere
and when I try to browse, its not working as expected

I am confused by how these ports work and how I can make this container work.

Please help. Thanks in Advance.

What I have tried:

<pre>ENV DOTNET_URLS=http://+:80
COPY bin/Release/netcoreapp2.1/publish/ /opt/Pcit/common
WORKDIR /opt/Pcit/common
ENTRYPOINT ["./pcit/common"]
EXPOSE 8080


<pre>Docker build -t common:v1 .


<pre>Docker run -p 8080:8080 imageid
Posted
Updated 22-May-23 1:34am

1 solution

"EXPOSE 8080" indicates that the application will listen for incoming network traffic on port 8080.

When running on localhost, you had :59901 port listening in, this means that you have another application that already makes use of port 8080, change the port number or stop the other application.

To see what app is using what port -
On MS Windows, select Start > All Programs > Accessories > System Tools >Resource Monitor

Expand the Network Tab

Move to the section for Listening Ports

Look in the Port column and scroll to find entry for port 8080

Select the given process and delete/kill the process or change your app port number.

As a side note, note that merely exposing a port in the container doesn't automatically make it accessible. You would still need to configure network bindings and firewall rules to allow inbound traffic to reach the container's exposed port.
 
Share this answer
 
Comments
ashu1810 22-May-23 8:07am    
Thanks for the reply,59901 is actually the port configured in Launchsettings.json in the project hence its using that port, can I make any changes in the docker file or while running the container to make it work, can you please suggest. I don't have access to Resource Monitor as we don't get admin rights on system.
Andre Oosthuizen 23-May-23 4:53am    
Assuming that you will want to still use a working port (59901), change 'EXPOSE 8080' to 'EXPOSE 59901'. Rebuild the Docker image using a cmd or similar prompt -
docker build -t imageid. 


Now tun the Docker Container -
docker run -p 59901:59901 imageid

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900