Home > front end >  Docker Container port access
Docker Container port access

Time:02-12

I have created an image from an existing dotnet application I can run locally.

in my docker file I have EXPOSE 5000

In the docker compose: ports: [5000:5000]

I start the container using the command: docker run -d -p 5000:5000 --name my-reports my-reports:latest

running the docker ps command :

     NAMES
106c4929c0d6   my-reports:latest   "dotnet my-reports"   8 minutes ago   Up 8 minutes   0.0.0.0:5000->5000/tcp   my-reports

The output of the entrypoint:

info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\app

netstat shows:

C:\app>netstat -a

Active Connections

  Proto  Local Address          Foreign Address        State
  TCP    0.0.0.0:135            106c4929c0d6:0         LISTENING
  TCP    0.0.0.0:5985           106c4929c0d6:0         LISTENING
  TCP    0.0.0.0:47001          106c4929c0d6:0         LISTENING
  TCP    0.0.0.0:49152          106c4929c0d6:0         LISTENING
  TCP    0.0.0.0:49153          106c4929c0d6:0         LISTENING
  TCP    0.0.0.0:49154          106c4929c0d6:0         LISTENING
  TCP    0.0.0.0:49155          106c4929c0d6:0         LISTENING
  TCP    0.0.0.0:49160          106c4929c0d6:0         LISTENING
  TCP    127.0.0.1:5000         106c4929c0d6:0         LISTENING

But I get timeouts trying to access the port from my machine via localhost:5000

CodePudding user response:

You have already provided flag --name my-reports but your container is reporting the name as "vpi-harmony-reports". Do kill the container and re-run the docker command. Also make sure you do not have firewall blocking 5000 port.

CodePudding user response:

Your problem is that your app listens on localhost. This is only available inside the container.

You need to make your app listen on the public network interface. Most easy achieved by using 0.0.0.0 as IP, which makes it listen on all interfaces.

In your case, make the app listen on 0.0.0.0:5000.

  • Related