microsoft / DockerTools

Tools For Docker, including Visual Studio Provisioning and Publishing
Other
173 stars 26 forks source link

`{ProjectDir\}.IdentityService\AzureServiceAuth\tokenprovider.json` created when container debug is started #387

Open ggirard07 opened 1 year ago

ggirard07 commented 1 year ago

I have a project in my solution that keeps creating a file at path {ProjectDir\}.IdentityService\AzureServiceAuth\tokenprovider.json every time I start a docker compose debug. The same file is not created when debugging the project directly without using Docker tooling. Any idea why it is happening to just one of the projects part of same solution & docker-compose?

@danegsta mentioned in this thread that it could be related to custom volume mount in docker compose. The only one I setup myself is for mounting dotnet secrets to my non-root user in containers with:

      volumes:
        - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro

I do not think this is related as all my projects use this mount but only a specific one is affected.

danegsta commented 1 year ago

@ggirard07 would you be able to share a snippet of the service configuration from your docker-compose for the specific impacted project?

ggirard07 commented 1 year ago

Here is the part relevant to the project involved. Please note in full docker compose I have multiple API projects involved, each with SQL migrations mounted in db container, but only a single API project has this file creation issue...

services:
  api:
      image: ${DOCKER_REGISTRY-}prj/api
      build:
        context: .
        dockerfile: src/My.API/Dockerfile
      environment:
        ASPNETCORE_ENVIRONMENT: ${ASPNETCORE_ENVIRONMENT}
        SqlContext: "cs"
      ports:
        - 18080:8080
      volumes:
        - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
      depends_on:
        sql:
          condition: service_healthy

  sql:
    image: ${DOCKER_REGISTRY-}prj/sql
    build:
      context: .
      dockerfile: tests/infrastructure/sql/Dockerfile
    environment:
      ACCEPT_EULA: Y
      SA_PASSWORD: ${SA_PASSWORD}
      MIGRATIONS_PATH: ${MIGRATIONS_PATH}
    init: true
    ports:
      - 8484:1433
    tmpfs:
      - /tmp/app
    volumes:
      - ./src/My.API/Migrations:${MIGRATIONS_PATH}/API:ro
    healthcheck:
      test: "[ -f /tmp/app/migrations.ready ]"
      interval: 5s
    cap_add:
      - "SYS_PTRACE"
danegsta commented 1 year ago

Can you start debugging the application and then either run docker container inspect <your api container> --format '{{json .Mounts}}' or open the Containers window in VS (View > Other > Containers), select the service container, and then select the volumes tab? If you can share the set of mounts, that'll help in troubleshooting, since VS generates its own volume mounts for debugging purposes in addition to what's in your config.

Also, can you share what .NET version you're targeting as well as the base image you are using in your Dockerfiles?

ggirard07 commented 1 year ago

Thanks I think I find the root cause of the issue thanks to your comment by comparing the mounts in the affected service vs the other services working properly. The problem was the mount I had for user secrets. In this service, I had a typo where secrets were mounted in /root instead of /home/root. Not sure why it triggered the issue on Visual Studio Docker tools side, but after fixing the mount path, the file is no longer being created as part of my project source code!