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;
}
Configure logging. Logging configuration is commonly provided by the Logging section of appsettings. ... Test the settings when using an app created with the ASP.NET Core web application templates. The dotnet run command must be run in the project directory after using set.
This post explores the building blocks upon which Docker logging is built, and how it relates to ASP.NET Core’s logging. Docker determines the destination for log messages via a logging driver.
Logging providers store logs, except for the Console provider which displays logs. For example, the Azure Application Insights provider stores logs in Azure Application Insights. Multiple providers can be enabled. The default ASP.NET Core web app templates: Use the Generic Host.
In the following example, a Serilog logger is used to log in CreateHostBuilder. AddSerilog uses the static configuration specified in Log.Logger: Constructor injection of a logger into Startup works in earlier versions of ASP.NET Core because a separate DI container is created for the Web Host.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With