Run docker containers without Visual Studio.

Simone Demuro 50 Reputation points
2023-07-25T13:47:13.47+00:00

I have a problem running any .Net project created in Visual Studio, without using Visual Studio UI to run the container.

In fact, the minimal reproductible steps are creating a new .net project and try to run the container using docker run or docker compose commands from the terminal.

Reproduction Steps:

Open Visual Studio and Create new project > ASP.NET Core Web Api > Keep the default configuration: WebApplication1 > .NET 7, configured for HTTPS, Enable for Docker (Linux), Controller, OpenApi Support.

Now we have a standard .NET API project. I defined the SSL port in the launch.settings.json so that every test can reuse the same url.

"Docker": {
       …
      "sslPort": 32769
}

Pressing the run button in Visual Studio opens up a browser at this url: https://localhost:32769/swagger/index.html that shows swagger working perfectly on the given port and in https

Now, I want to run this container without Visual Studio. For this reason I intercepted the run command that Visual Studio claims to run when starting the debugger (intercepting it from visual studio container tools)

1>docker run -dt -v "C:\Users\demur\vsdbg\vs2017u5:/remote_debugger:rw" -v "C:\Users\demur\AppData\Roaming\Microsoft\UserSecrets:/root/.microsoft/usersecrets:ro" -v "C:\Users\demur\AppData\Roaming\ASP.NET\Https:/root/.aspnet/https:ro" -v "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Sdks\Microsoft.Docker.Sdk\tools\TokenService.Proxy\linux-x64\net7.0:/TokenService.Proxy:ro" -v "C:\Users\demur\source\repos\WebApplication1\WebApplication1:/app" -v "C:\Users\demur\source\repos\WebApplication1:/src/" -v "C:\Users\demur\.nuget\packages\:/root/.nuget/fallbackpackages" -e "ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS=true" -e "ASPNETCORE_ENVIRONMENT=Development" -e "ASPNETCORE_URLS=https://+:443;http://+:80" -e "ASPNETCORE_HTTPS_PORT=32769" -e "DOTNET_USE_POLLING_FILE_WATCHER=1" -e "NUGET_PACKAGES=/root/.nuget/fallbackpackages" -e "NUGET_FALLBACK_PACKAGES=/root/.nuget/fallbackpackages" -p 32769:443 -P --name WebApplication1 --entrypoint tail webapplication1:dev -f /dev/null

1>docker run -dt -v "C:\Users\demur\vsdbg\vs2017u5:/remote_debugger:rw" -v "C:\Users\demur\AppData\Roaming\Microsoft\UserSecrets:/root/.microsoft/usersecrets:ro" -v "C:\Users\demur\AppData\Roaming\ASP.NET\Https:/root/.aspnet/https:ro" -v "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Sdks\Microsoft.Docker.Sdk\tools\TokenService.Proxy\linux-x64\net7.0:/TokenService.Proxy:ro" -v "C:\Users\demur\source\repos\WebApplication1\WebApplication1:/app" -v "C:\Users\demur\source\repos\WebApplication1:/src/" -v "C:\Users\demur\.nuget\packages\:/root/.nuget/fallbackpackages" -e "ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS=true" -e "ASPNETCORE_ENVIRONMENT=Development" -e "ASPNETCORE_URLS=https://+:443;http://+:80" -e "ASPNETCORE_HTTPS_PORT=32769" -e "DOTNET_USE_POLLING_FILE_WATCHER=1" -e "NUGET_PACKAGES=/root/.nuget/fallbackpackages" -e "NUGET_FALLBACK_PACKAGES=/root/.nuget/fallbackpackages" -p 32769:443 -P --name WebApplication1 --entrypoint tail webapplication1:dev -f /dev/null

So I delete Visual studio container, and run that command, a new container is created, but the browser on https://localhost:32769/swagger/index.html gives connection refused.

I tried playing with the arguments passed to the docker run, but I wasn't able to make one that works.

How can I run a simple .NET 7 project image in docker without visual studio?

Developer technologies | ASP.NET | ASP.NET Core
Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other
A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} vote

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.