microsoft / DockerTools

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

Please change the docker-compose.exe command line #106

Closed hodgsopg closed 1 year ago

hodgsopg commented 6 years ago
  1. This currently loads: docker-compose.yml followed by docker-compose.override.yml followed by the generated docker-compose (e.g. docker-compose.vs.debug.g.yml)
  2. Could you change it so the override file is last: docker-compose.yml followed by the generated docker-compose (e.g. docker-compose.vs.debug.g.yml) followed by docker-compose.override.yml
  3. Or add an extra override file that is called last: docker-compose.yml followed by docker-compose.override.yml followed by the generated docker-compose (e.g. docker-compose.vs.debug.g.yml) followed by docker-compose.final-override.yml
  4. Or move the docker-compose command line into the dcproj file so we can modify it.

When debugging it generates a docker-compose.vs.target.g.yml file that is called last on the command line, so overrides any user options. This seems to do the following:

  1. Specify the target to the first section of the Dockerfile, this means only the first FROM section of the Dockerfile is used.
  2. Mount the project directory to /app
  3. Override the entrypoint
  4. Specify the arguments that are passed to the debugged program.
  5. Specify the working directory to /app.

I can find no mechanism to specify any of these options.

Philip

aaroncoville commented 6 years ago

Yes! I wasted entirely too much time trying to figure out why my multi-stage dockerfile would not work and it's because of this. The VS DockerTools ignore most of my DockerFile and only run the first FROM section.

This is a huge problem, the default DockerFiles generated by VS when you 'Add Docker Support' don't work if you are relying on anything that doesn't exist in that base docker image.

hodgsopg commented 6 years ago

Actually there is a workaround for this.

  1. add files docker-compose.vs.debug.yml and docker-compose.vs.release.yml into your docker compose project
  2. copy the contents of docker-compose.vs.debug.g.yml and docker-compose.vs.release.g.yml into these files
  3. make the changes you want to make
  4. remove the leaf lines from these files that have not changed.

The docker-compose.vs.debug.yml and docker-compose.vs.release.yml files get added at the end of the docker compose command line.

So you can have a file with this:

version: '3.4'
services:
  projectname:
    build:
      target: final

and it will target final instead of the first block

I found this by reverse engineering the code, It would be useful if this was documented.

aaroncoville commented 6 years ago

@philip-hodgson Thank you so much - this workaround works great!

For anyone else who runs into this, I initially ran into problems of docker complaining about a version mismatch between the compose files when I created a new docker.compose.vs.debug.yml file and copied the contents from the docker-compose.vs.debug.g.yml file. This was solved by copying the actual docker-compose.vs.debug.g.yml file from the obj directory, renaming it and then adding that to the docker-compose project.

steveoh commented 6 years ago

is this why this output still runs using the development environment?

Build started 6/21/2018 6:00:22 PM.
__________________________________________________
Project "/Users/sgourley/Projects/webapi-core/docker-compose.dcproj" (Build target(s)):

Target DockerGetServiceReferences:
    docker-compose  -f "/Users/sgourley/Projects/webapi-core/docker-compose.yml" -f "/Users/sgourley/Projects/webapi-core/docker-compose.override.yml" -p dockercompose9758618965843433410 --no-ansi config
    services:
      cache:
        image: redis:latest
      db:
        environment:
          POSTGRES_DB: webapi
          POSTGRES_USER: postgres
        image: postgres:10.4
        ports:
        - published: 5432
          target: 5432
        volumes:
        - pgdata:/var/lib/postgresql/data:rw
      webapi-core:
        build:
          context: /Users/sgourley/Projects/webapi-core
          dockerfile: api.mapserv.utah.gov/Dockerfile
        depends_on:
        - cache
        - db
        environment:
          ASPNETCORE_ENVIRONMENT: Staging
          ASPNETCORE_URLS: http://+:1337
        image: webapi
        links:
        - cache
        - db
        ports:
        - published: 1337
          target: 1337
    version: '3.6'
    volumes:
      pgdata:
        external: true
        name: pgdata
Target DockerResolveAppType:
    __________________________________________________
    Project "/Users/sgourley/Projects/webapi-core/docker-compose.dcproj" is building "/Users/sgourley/Projects/webapi-core/api.mapserv.utah.gov/api.mapserv.utah.gov.csproj" (DockerResolveAppType target(s)):

Target DockerResolveTargetFramework:
    __________________________________________________
    Project "/Users/sgourley/Projects/webapi-core/docker-compose.dcproj" is building "/Users/sgourley/Projects/webapi-core/api.mapserv.utah.gov/api.mapserv.utah.gov.csproj" (DockerResolveTargetFramework target(s)):

Target DockerResolveProjectInputAndOutput:
    __________________________________________________
    Project "/Users/sgourley/Projects/webapi-core/docker-compose.dcproj" is building "/Users/sgourley/Projects/webapi-core/api.mapserv.utah.gov/api.mapserv.utah.gov.csproj" (DockerResolveProjectInputAndOutput target(s)):

Target DockerPrepareForBuild:
    docker-compose  -f "/Users/sgourley/Projects/webapi-core/docker-compose.yml" -f "/Users/sgourley/Projects/webapi-core/docker-compose.override.yml" -f "/Users/sgourley/Projects/webapi-core/obj/Docker/docker-compose.vs.debug.g.yml" -f "/Users/sgourley/Projects/webapi-core/docker-compose.vs.debug.yml" -p dockercompose9758618965843433410 --no-ansi config
    services:
      cache:
        image: redis:latest
      db:
        environment:
          POSTGRES_DB: webapi
          POSTGRES_USER: postgres
        image: postgres:10.4
        ports:
        - published: 5432
          target: 5432
        volumes:
        - pgdata:/var/lib/postgresql/data:rw
      webapi-core:
        build:
          context: /Users/sgourley/Projects/webapi-core
          dockerfile: api.mapserv.utah.gov/Dockerfile
          target: base
        depends_on:
        - cache
        - db
        entrypoint: tail -f /dev/null
        environment:
          ASPNETCORE_ENVIRONMENT: DockerDevelopment
          ASPNETCORE_URLS: http://+:1337
          DOTNET_USE_POLLING_FILE_WATCHER: '1'
          NUGET_FALLBACK_PACKAGES: /root/.nuget/fallbackpackages
        image: webapi:dev
        labels:
          com.microsoft.visualstudio.debuggee.arguments: ' --additionalProbingPath /root/.nuget/packages
            --additionalProbingPath /root/.nuget/fallbackpackages  bin/Debug/netcoreapp2.1/api.mapserv.utah.gov.dll'
          com.microsoft.visualstudio.debuggee.killprogram: /bin/bash -c "if PID=$$(pidof
            -x dotnet); then kill $$PID; fi"
          com.microsoft.visualstudio.debuggee.program: dotnet
          com.microsoft.visualstudio.debuggee.workingdirectory: /app
        links:
        - cache
        - db
        ports:
        - published: 1337
          target: 1337
        volumes:
        - /Users/sgourley/Projects/webapi-core/api.mapserv.utah.gov:/app:rw
        - /Users/sgourley/.vsdbg/vs2017u5:/remote_debugger:ro
        - /usr/local/share/dotnet/sdk/NuGetFallbackFolder:/root/.nuget/fallbackpackages:ro
        - /Users/sgourley/.nuget/packages:/root/.nuget/packages:ro
    version: '3.6'
    volumes:
      pgdata:
        external: true
        name: pgdata
    docker ps --filter "status=running" --filter "name=dockercompose9758618965843433410_webapi-core_" --format {{.ID}} -n 1
Target DockerBuildServiceReferences:
    __________________________________________________
    Project "/Users/sgourley/Projects/webapi-core/docker-compose.dcproj" is building "/Users/sgourley/Projects/webapi-core/api.mapserv.utah.gov/api.mapserv.utah.gov.csproj" (Build target(s)):

    Target _HandlePackageFileConflicts:
        Encountered conflict between 'Reference:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/microsoft.netcore.app/2.1.0/ref/netcoreapp2.1/System.Collections.Immutable.dll' and 'Reference:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/system.collections.immutable/1.5.0/lib/netstandard2.0/System.Collections.Immutable.dll'.  Choosing 'Reference:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/microsoft.netcore.app/2.1.0/ref/netcoreapp2.1/System.Collections.Immutable.dll' because it comes from a package that is preferred.
        Encountered conflict between 'Reference:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/microsoft.netcore.app/2.1.0/ref/netcoreapp2.1/System.Diagnostics.DiagnosticSource.dll' and 'Reference:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/system.diagnostics.diagnosticsource/4.5.0/lib/netstandard1.3/System.Diagnostics.DiagnosticSource.dll'.  Choosing 'Reference:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/microsoft.netcore.app/2.1.0/ref/netcoreapp2.1/System.Diagnostics.DiagnosticSource.dll' because it comes from a package that is preferred.
        Encountered conflict between 'Reference:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/microsoft.netcore.app/2.1.0/ref/netcoreapp2.1/System.Linq.Parallel.dll' and 'Reference:/Users/sgourley/.nuget/packages/system.linq.parallel/4.3.0/ref/netstandard1.1/System.Linq.Parallel.dll'.  Choosing 'Reference:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/microsoft.netcore.app/2.1.0/ref/netcoreapp2.1/System.Linq.Parallel.dll' because AssemblyVersion '4.0.3.0' is greater than '4.0.0.0'.
        Encountered conflict between 'Reference:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/microsoft.netcore.app/2.1.0/ref/netcoreapp2.1/System.Net.Http.dll' and 'Reference:/Users/sgourley/.nuget/packages/system.net.http/4.3.1/ref/netstandard1.3/System.Net.Http.dll'.  Choosing 'Reference:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/microsoft.netcore.app/2.1.0/ref/netcoreapp2.1/System.Net.Http.dll' because AssemblyVersion '4.2.1.0' is greater than '4.1.1.0'.
        Encountered conflict between 'Reference:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/microsoft.netcore.app/2.1.0/ref/netcoreapp2.1/System.Reflection.Metadata.dll' and 'Reference:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/system.reflection.metadata/1.6.0/lib/netstandard2.0/System.Reflection.Metadata.dll'.  Choosing 'Reference:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/microsoft.netcore.app/2.1.0/ref/netcoreapp2.1/System.Reflection.Metadata.dll' because it comes from a package that is preferred.
        Encountered conflict between 'Reference:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/microsoft.netcore.app/2.1.0/ref/netcoreapp2.1/System.Runtime.Serialization.Xml.dll' and 'Reference:/Users/sgourley/.nuget/packages/system.runtime.serialization.xml/4.3.0/ref/netstandard1.3/System.Runtime.Serialization.Xml.dll'.  Choosing 'Reference:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/microsoft.netcore.app/2.1.0/ref/netcoreapp2.1/System.Runtime.Serialization.Xml.dll' because AssemblyVersion '4.1.4.0' is greater than '4.1.1.0'.
        Encountered conflict between 'Platform:Microsoft.Win32.Registry.dll' and 'Runtime:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/microsoft.win32.registry/4.5.0/lib/netstandard2.0/Microsoft.Win32.Registry.dll'.  Choosing 'Platform:Microsoft.Win32.Registry.dll' because it comes from a package that is preferred.
        Encountered conflict between 'Platform:System.Collections.Immutable.dll' and 'Runtime:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/system.collections.immutable/1.5.0/lib/netstandard2.0/System.Collections.Immutable.dll'.  Choosing 'Platform:System.Collections.Immutable.dll' because it comes from a package that is preferred.
        Encountered conflict between 'Platform:System.Diagnostics.DiagnosticSource.dll' and 'Runtime:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/system.diagnostics.diagnosticsource/4.5.0/lib/netstandard1.3/System.Diagnostics.DiagnosticSource.dll'.  Choosing 'Platform:System.Diagnostics.DiagnosticSource.dll' because it comes from a package that is preferred.
        Encountered conflict between 'Platform:System.Linq.Parallel.dll' and 'Runtime:/Users/sgourley/.nuget/packages/system.linq.parallel/4.3.0/lib/netstandard1.3/System.Linq.Parallel.dll'.  Choosing 'Platform:System.Linq.Parallel.dll' because AssemblyVersion '4.0.3.0' is greater than '4.0.2.0'.
        Encountered conflict between 'Platform:System.Reflection.Metadata.dll' and 'Runtime:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/system.reflection.metadata/1.6.0/lib/netstandard2.0/System.Reflection.Metadata.dll'.  Choosing 'Platform:System.Reflection.Metadata.dll' because it comes from a package that is preferred.
        Encountered conflict between 'Platform:System.Runtime.Serialization.Xml.dll' and 'Runtime:/Users/sgourley/.nuget/packages/system.runtime.serialization.xml/4.3.0/lib/netstandard1.3/System.Runtime.Serialization.Xml.dll'.  Choosing 'Platform:System.Runtime.Serialization.Xml.dll' because AssemblyVersion '4.1.4.0' is greater than '4.1.2.0'.
        Encountered conflict between 'Platform:System.Security.AccessControl.dll' and 'Runtime:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/system.security.accesscontrol/4.5.0/lib/netstandard2.0/System.Security.AccessControl.dll'.  Choosing 'Platform:System.Security.AccessControl.dll' because it comes from a package that is preferred.
        Encountered conflict between 'Platform:System.Security.Cryptography.Cng.dll' and 'Runtime:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/system.security.cryptography.cng/4.5.0/lib/netcoreapp2.1/System.Security.Cryptography.Cng.dll'.  Choosing 'Platform:System.Security.Cryptography.Cng.dll' because it comes from a package that is preferred.
        Encountered conflict between 'Platform:System.Security.Principal.Windows.dll' and 'Runtime:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/system.security.principal.windows/4.5.0/lib/netstandard2.0/System.Security.Principal.Windows.dll'.  Choosing 'Platform:System.Security.Principal.Windows.dll' because it comes from a package that is preferred.
        Encountered conflict between 'Platform:Microsoft.Win32.Registry.dll' and 'Runtime:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/microsoft.win32.registry/4.5.0/runtimes/unix/lib/netstandard2.0/Microsoft.Win32.Registry.dll'.  Choosing 'Platform:Microsoft.Win32.Registry.dll' because it comes from a package that is preferred.
        Encountered conflict between 'Platform:Microsoft.Win32.Registry.dll' and 'Runtime:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/microsoft.win32.registry/4.5.0/runtimes/win/lib/netstandard2.0/Microsoft.Win32.Registry.dll'.  Choosing 'Platform:Microsoft.Win32.Registry.dll' because it comes from a package that is preferred.
        Encountered conflict between 'Platform:System.Net.Http.dll' and 'Runtime:/Users/sgourley/.nuget/packages/system.net.http/4.3.1/runtimes/unix/lib/netstandard1.6/System.Net.Http.dll'.  Choosing 'Platform:System.Net.Http.dll' because AssemblyVersion '4.2.1.0' is greater than '4.1.1.0'.
        Encountered conflict between 'Platform:System.Net.Http.dll' and 'Runtime:/Users/sgourley/.nuget/packages/system.net.http/4.3.1/runtimes/win/lib/netstandard1.3/System.Net.Http.dll'.  Choosing 'Platform:System.Net.Http.dll' because AssemblyVersion '4.2.1.0' is greater than '4.1.1.0'.
        Encountered conflict between 'Platform:System.Security.AccessControl.dll' and 'Runtime:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/system.security.accesscontrol/4.5.0/runtimes/win/lib/netcoreapp2.0/System.Security.AccessControl.dll'.  Choosing 'Platform:System.Security.AccessControl.dll' because it comes from a package that is preferred.
        Encountered conflict between 'Platform:System.Security.Cryptography.Cng.dll' and 'Runtime:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/system.security.cryptography.cng/4.5.0/runtimes/win/lib/netcoreapp2.1/System.Security.Cryptography.Cng.dll'.  Choosing 'Platform:System.Security.Cryptography.Cng.dll' because it comes from a package that is preferred.
        Encountered conflict between 'Platform:System.Security.Principal.Windows.dll' and 'Runtime:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/system.security.principal.windows/4.5.0/runtimes/unix/lib/netcoreapp2.0/System.Security.Principal.Windows.dll'.  Choosing 'Platform:System.Security.Principal.Windows.dll' because it comes from a package that is preferred.
        Encountered conflict between 'Platform:System.Security.Principal.Windows.dll' and 'Runtime:/usr/local/share/dotnet/sdk/NuGetFallbackFolder/system.security.principal.windows/4.5.0/runtimes/win/lib/netcoreapp2.0/System.Security.Principal.Windows.dll'.  Choosing 'Platform:System.Security.Principal.Windows.dll' because it comes from a package that is preferred.
    Target GenerateTargetFrameworkMonikerAttribute:
      Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
    Target _CoreGenerateRazorAssemblyInfo:
      Skipping target "_CoreGenerateRazorAssemblyInfo" because all output files are up-to-date with respect to the input files.
    Target CoreGenerateUserSecretsAttribute:
      Skipping target "CoreGenerateUserSecretsAttribute" because all output files are up-to-date with respect to the input files.
    Target CoreGenerateAssemblyInfo:
      Skipping target "CoreGenerateAssemblyInfo" because all output files are up-to-date with respect to the input files.
    Target CoreCompile:
      Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files.
    Target GenerateBuildDependencyFile:
      Skipping target "GenerateBuildDependencyFile" because all output files are up-to-date with respect to the input files.
    Target GenerateBuildRuntimeConfigurationFiles:
      Skipping target "GenerateBuildRuntimeConfigurationFiles" because all output files are up-to-date with respect to the input files.
    Target CopyFilesToOutputDirectory:
        api.mapserv.utah.gov -> /Users/sgourley/Projects/webapi-core/api.mapserv.utah.gov/bin/Debug/netcoreapp2.1/api.mapserv.utah.gov.dll
Target DockerUpdateComposeVsGeneratedFiles:
    __________________________________________________
    Project "/Users/sgourley/Projects/webapi-core/docker-compose.dcproj" is building "/Users/sgourley/Projects/webapi-core/api.mapserv.utah.gov/api.mapserv.utah.gov.csproj" (DockerUpdateComposeVsGeneratedFiles target(s)):

    Copying file from "/Users/sgourley/Projects/webapi-core/obj/Docker/docker-compose.vs.debug.partial.g.yml" to "/Users/sgourley/Projects/webapi-core/obj/Docker/docker-compose.vs.debug.g.yml".
    Copying file from "/Users/sgourley/Projects/webapi-core/obj/Docker/docker-compose.vs.release.partial.g.yml" to "/Users/sgourley/Projects/webapi-core/obj/Docker/docker-compose.vs.release.g.yml".
Target DockerPrepareForLaunch:
    docker-compose  -f "/Users/sgourley/Projects/webapi-core/docker-compose.yml" -f "/Users/sgourley/Projects/webapi-core/docker-compose.override.yml" -f "/Users/sgourley/Projects/webapi-core/obj/Docker/docker-compose.vs.debug.g.yml" -f "/Users/sgourley/Projects/webapi-core/docker-compose.vs.debug.yml" -p dockercompose9758618965843433410 --no-ansi up -d --build --force-recreate --remove-orphans
    Building webapi-core
    Step 1/2 : FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
     ---> 5b7745597818
    Step 2/2 : WORKDIR /app
     ---> Using cache
     ---> 7ae7e40583c1
    Successfully built 7ae7e40583c1
    Successfully tagged webapi:dev
    Recreating dockercompose9758618965843433410_db_1 ... 
    Recreating dockercompose9758618965843433410_cache_1 ... 
    Recreating dockercompose9758618965843433410_db_1    ... done
    Recreating dockercompose9758618965843433410_cache_1 ... done
    Recreating dockercompose9758618965843433410_webapi-core_1 ... 
    Recreating dockercompose9758618965843433410_webapi-core_1 ... done

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:05.17

---------------------- Done ----------------------

Build successful.
Hosting environment: Development
Content root path: /app
Now listening on: http://[::]:1337
Application started. Press Ctrl+C to shut down.

When run from visual studio?

It's clearly set to Staging and then overridden to DockerDevelopment but the app still runs as Development

JPThorne commented 6 years ago

Has there been any official resolution of this issue? Any feedback from the devs on linked issues? Not really sure what the point of 'add docker support' in VS is if it's just going to ignore anything the dev puts in the local files?

laconictae commented 5 years ago

I've spent entirely too much time trying to find a workaround to this... currently my issue is that no volumes I specify in docker-compose.yml or docker-compose.override.yml are actually used when VS fires off docker run. I believe it's related to the generated docker-compose files that VS creates, but no amount of editing those or moving them (as suggested by philip-hodgson above) has had any effect. In fact the run command I see VS firing has volumes specified that I can't find anywhere in the solution, and it stoicly ignores the volumes I specify.

I've attempted a debug profile with a powershell script that builds and runs the containers with the correct volumes, but then I lose debugging and haven't been able to get that working again.

Has anyone found a way around this?

EriksonBahr commented 5 years ago

@laconictae the volumes are defined on "obj\Docker\docker-compose.vs.debug.g.yml". If you want to override it you need to add this same file content but named as docker-compose.vs.debug.yml in your docker-compose project, then you can remove anything you want...

I had a different situation where I also spent quite few time: My project root path was "F:\Git\c#\myProject\" where I realized the "docker-compose.vs.debug.g.yml" cannot handle this c# in the path. The result was my volume was being created as "- F:\Git\c\myProject\src:/app". Changing the path to "F:\Git**csharp**\myProject\" fixed all my issues, I did not even need to make the workaround suggested by @philip-hodgson.

Environment: win10 - 1803; VS 2017

dbreshears commented 1 year ago

Closing as you can add the override files from context menu in VS 2022 latest version