I am trying to deploy api's on Docker desktop Have successfully deployed to Docker Desktop image and container and than successfully pushed to Docker Hub it is also showing running but am not able to view it in the browser
These are docker desktop images
When i go to my inuse of First service it is showing me this can any one explain how he got his name
And inside it's showing like this why the port 8080
2024-11-10 15:11:51 info: Microsoft.EntityFrameworkCore.Update[30100]
2024-11-10 15:11:51 Saved 3 entities to in-memory store.
2024-11-10 15:11:51 info: Microsoft.Hosting.Lifetime[14]
2024-11-10 15:11:51 Now listening on: http://[::]:8080
2024-11-10 15:11:51 info: Microsoft.Hosting.Lifetime[0]
2024-11-10 15:11:51 Application started. Press Ctrl+C to shut down.
2024-11-10 15:11:51 info: Microsoft.Hosting.Lifetime[0]
2024-11-10 15:11:51 Hosting environment: Production
2024-11-10 15:11:51 info: Microsoft.Hosting.Lifetime[0]
2024-11-10 15:11:51 Content root path: /app
2024-11-10 15:12:14 info: Microsoft.Hosting.Lifetime[0]
2024-11-10 15:12:14 Application is shutting down...
2024-11-10 15:12:16 info: Microsoft.EntityFrameworkCore.Update[30100]
2024-11-10 15:12:16 Saved 3 entities to in-memory store.
2024-11-10 15:12:16 info: Microsoft.Hosting.Lifetime[14]
2024-11-10 15:12:16 Now listening on: http://[::]:8080
2024-11-10 15:12:16 info: Microsoft.Hosting.Lifetime[0]
2024-11-10 15:12:16 Application started. Press Ctrl+C to shut down.
2024-11-10 15:12:16 info: Microsoft.Hosting.Lifetime[0]
2024-11-10 15:12:16 Hosting environment: Production
2024-11-10 15:12:16 info: Microsoft.Hosting.Lifetime[0]
2024-11-10 15:12:16 Content root path: /app
But the command i have run for docker port is this docker run -p 8082:82 -d aiftekhar/platformservice
previously i have ran it into multiple ports but it is running why can't i view it in the browser with
http://127.0.0.1:8080/swagger/index.html
Locally it is accessible like this
http://localhost:5098/swagger/index.html
Please help me i am learning docker that's my 3rd time just trying to have some good concepts here
As you can see from the log message, your app is listening on port 8080.
2024-11-10 15:11:51 info: Microsoft.Hosting.Lifetime[14]
2024-11-10 15:11:51 Now listening on: http://[::]:8080
Listening on port 8080 is the default for dockerized .NET 8 applications.
That may be different from when you were developing it, as Visual Studio changes how your container runs based on your launch settings.
Another thing to be aware of is that Swagger is only available in development environments by default. If you look in your Program.cs file, there should be some code like this
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
As you can see, Swagger is only set up if the app is running in a development environment. Docker is normally not considered a development environment. The reason for disabling Swagger in production is that people often don't want to publish their full API definition to the public.
To enable Swagger, you can set the environment variable ASPNETCORE_ENVIRONMENT to the value 'Development'.
With the changed port and the environment variable, your command to run the container should look like this
docker run -p 8082:8080 -e ASPNETCORE_ENVIRONMENT=Development -d aiftekhar/platformservice
Your API, including Swagger, should then be available on
http://localhost:8082/swagger/index.html