10

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     
Kyle Johnson
  • 101
  • 1
  • 1
  • 5

4 Answers4

4

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

diegosasw
  • 13,734
  • 16
  • 95
  • 159
1

See this answer.

The base dotnet image overrides the default kestrel port. Why, I don't know. Adding the environment declaration to my docker file fixed the problem for me.

Nick Murphy
  • 129
  • 1
  • 6
0

if you are runnig a .NET application, try to verify those points:

1)

    Class Program
    { ...
            // Configure the HTTP request pipeline.
            //if (app.Environment.IsDevelopment())
            //{
                app.UseSwagger();
                app.UseSwaggerUI();
            //}

Comment your code like mine.

  1. Verify if you are using a port binding, like
 -p 8088:80 -p 8043:443
  1. Open your browser like localhost:PORT
Felipe Augusto
  • 1,341
  • 1
  • 16
  • 18
-1

It's trying to use the IPv6 protocol on the network interface. Disable IPv6 and restart docker. It also looks like you might have both apps trying to use port 80. You can only serve one item on a given port with a given interface/IP. Try setting the API to use a different port number, like 8080.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
  • I am not entirely sure how to disable IPv6 for this container As for the ports I think I have them setup on separate ports, 8080, and 8081 using the compose yml which i posted in the edit to the question above. Thanks for your reply. – Kyle Johnson Jun 26 '18 at 05:02
  • @KyleJohnson `Now listening on: http://[::]:80` tells me it's trying to use port 80. – Joel Coehoorn Jun 26 '18 at 13:27