skip to Main Content

I have a basic docker-compose setup to run the SQL server and the app. When I run an application via run with Docker compose it works as expected, automatically opens the browser and redirects to swagger UI. But when running from CLI via docker compose up --build it builds db and app and I can see them running in Docker desktop but can’t reach out by the given port on docker-compose. Below is the docker-compose file :

services:
  app.api:
    container_name: app.api
    image: '${DOCKER_REGISTRY-}appapi'
    build:
      context: .
      dockerfile: App.Api/Dockerfile
    ports:
      - '5000:80'
    depends_on:
      - app.database
    environment:
      - ASPNETCORE_ENVIRONMENT=Local
  app.database:
    container_name: app.database
    image: 'mcr.microsoft.com/mssql/server:2019-latest'
    restart: always
    ports:
      - '1433:1433'
    environment:
      - ACCEPT_EULA=Y
      - SA_PASSWORD=RSNkHXW1
    volumes:
      - 'sql-data:/var/opt/mssql'
volumes:
  sql-data: 

I tried to change ports and setting up network inside docker compose but no changes.P.s : I set env to local and in program.cs I check if the env is non-production and add Swagger

2

Answers


  1. By default, Swagger is only available when your app is running in development mode.

    Instead of setting your environment to Local, set it to Development like this

           - ASPNETCORE_ENVIRONMENT=Development
    

    If you prefer to have Swagger available always, no matter the environment, you can change the code in Program.cs that sets it up.

    Login or Signup to reply.
  2. The default docker file generated from visual studio used command like

    FROM build AS publish
    RUN dotnet publish "WebApplication98.csproj" -c Release -o /app/publish /p:UseAppHost=false
    

    "dotnet publish -c Release" could be change to "dotnet publish -c Debug" to specify the a development image.

    You could check the "dotnet publish" configuration from here https://learn.microsoft.com/th-th/dotnet/core/tools/dotnet-publish#options

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search