8

Hello i have the following problem:

I have a ASP .NET Core server that is docker-ized and runs in a container with docker-compose.I send requests to my server via postman and i get 500-internal server error.

I have tried:

  • docker attach myserver and i get nothing in the console.
  • docker logs myserver i will get only the initial log (the startup).
  • telnet hostname port and it seems it works to connect but i do not know how to create the request.

How can i get my hands on the console of my ASP .NET Core server?

docker-compose

version: '3.3'
services:
    db:
      image: redis:4.0.5-alpine
      container_name: redis0

      networks: 
        - redis-net
      ports:
        - 6381:6379

    backend:
      image: server
      container_name: server0
      build: ./Server
      command: ["dotnet","Server.dll"]
      depends_on:
        - db
      ports:
        - 9400:9300
      networks:
        - redis-net

networks:
    redis-net:

dockerfile (for server)

FROM microsoft/dotnet:2.1-aspnetcore-runtime 
WORKDIR /app
COPY ./publish /app
EXPOSE 9300

Startup.cs

public static IWebHostBuilder CreateWebHostBuilder(string[] args) {
            string port="9300";
            var builder = new WebHostBuilder();
            builder.UseStartup<Startup>();
            var url =$"http://0.0.0.0:{port.ToString()}/";//Address.Default.ToUrl();
            Debug.WriteLine(url);
            builder.UseKestrel().UseUrls(url);
            return builder;

        }

1 Answer 1

15
  • Configure your .net core app to print logs to the console

    E.g. Console.WriteLine("Some application log");

  • Rebuild & run the containers

    docker-compose build

    docker-compose up

  • Get the container-id for the running server container using

    docker ps

  • Run this in another command window to follow the logs

    docker logs --follow <container-id>

  • Run this to get into the container's bash shell

    docker exec -it <container-id> bash

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.