Access Swagger in Azure Container Instance

  azure, azure-devops, c#, docker, swagger

I have a webapi running in Auzure Container Instances with open api enabled. But I can’t access swagger?

I can navigate to the controller and see output: http://brajzoredockerapi.northeurope.azurecontainer.io/weatherforecast/ (works)

But i can’t reach this page:
http://brajzoredockerapi.northeurope.azurecontainer.io/swagger/

How can I use swagger within Auzure Container Instances?

Here is my Startup.cs:

 public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {

        services.AddControllers();
        services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new OpenApiInfo { Title = "WebApplication2", Version = "v1" });
        });
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseSwagger();
            app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebApplication2 v1"));
        }

        app.UseRouting();

        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });
    }
}

It works when i start the application locally.

Source: Docker Questions

LEAVE A COMMENT