Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Container Listening on http://[::]:80

I am working on setting up two Docker containers using Docker for Windows. A simple node based web app, and a dotnet core API application. I am starting both these containers using "docker-compose up". The node app starts up perfectly and I can hit the exposed URL, however the dotnet app isn't seeming to work.

The output of the docker-compose up command is below:

application.client_1  | INFO: Accepting connections at http://localhost:8080
application.api_1     | warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
application.api_1     |       No XML encryptor configured. Key {cc83a8ac-e1de-4eb3-95ab-8c69a5961bf9} may be persisted to storage in unencrypted form.
application.api_1     | Hosting environment: Development
application.api_1     | Content root path: /app/application.Api
application.api_1     | Now listening on: http://[::]:80
application.api_1     | Application started. Press Ctrl+C to shut down.

The Docker file looks like the following:

FROM microsoft/dotnet AS build
WORKDIR /app
ENV PORT=8081

COPY application.Api/application.Api.csproj application.Api/
COPY application.Business/application.Business.csproj application.Business/
COPY application.DataAccess/application.DataAccess.csproj application.DataAccess/
COPY application.DataModel/application.DataModel.csproj application.DataModel/
WORKDIR /app/application.Api
RUN dotnet restore

WORKDIR /app/
COPY application.Api/. ./application.Api/
COPY application.Business/. ./application.Business/
COPY application.DataAccess/. ./application.DataAccess/
COPY application.DataModel/. ./application.DataModel/
WORKDIR /app/application.Api
RUN dotnet publish -c Release -o out

FROM microsoft/dotnet AS runtime
WORKDIR /app/application.Api
COPY --from=build /app/application.Api/out .
ENTRYPOINT ["dotnet", "application.Api.dll" ]
EXPOSE $PORT

I am unable to get an IP and thus hit the API url. Any thoughts would be much appreciated as I am pretty new to Docker.


UPDATE 1: Compose YML

version: '3.4'

services:
  tonquin.api:
    image: application.api
    ports: 
      - 8081:5000
    build:
      context: .
      dockerfile: Dockerfile

  tonquin.client:
    image: application.client
    ports: 
      - 8080:8080
    build:
      context: .
      dockerfile: ../application.Client/Dockerfile     
like image 734
Kyle Johnson Avatar asked Jun 25 '18 23:06

Kyle Johnson


People also ask

Does Docker use port 80?

By default, the httpd server listens on port 80. It's not mandatory to perform port mapping for all Docker containers. Often, we will avoid opening host ports in order to keep the services of the container private or only visible to sibling containers in the same Docker network.

What is the significance of 80 8080 when used in the Docker?

In your case, -p 8080:80 means leading all traffic to port 80 in container. If you check port status on host by netstat -lntp|grep 8080 , there is a process managed by docker-proxy who is listening on port 8080 on host machine. It would manage all traffic routing between port 8080 on host and port 80 in container.

What port is Docker listening on?

The Docker client will default to connecting to unix:///var/run/docker.sock on Linux, and tcp://127.0.0.1:2376 on Windows. For example: tcp:// -> TCP connection to 127.0.0.1 on either port 2376 when TLS encryption is on, or port 2375 when communication is in plain text.


1 Answers

As they've mentioned it seems your container is running on port 80. So for whatever reason that's the port being exposed. Maybe the EXPOSE $PORT is not returning 8081 as you expect?

When you run the container, unless you specify where to map it, it will only be available at the container's IP at the exposed port (80 in your case). Find out this container Ip easily by running docker inspect <container_id>

Test your image by doing something like docker run -p 8080:80 yourimage. You'll see that in addition to the port 80 that the image exposes, it is being mapped to your local port 8080 so that http://localhost:8080 should be reachable.

See this in case it helps you

like image 83
diegosasw Avatar answered Oct 07 '22 09:10

diegosasw