Reputation: 15103
I am starting with dockers so i create a basic dotnet core console app, to use as a pathfinder. Then i add docker-compose support targeting windows containers.
I can build and run the image from the visual studio, even debug de app. But when i try to run the same app from docker CLI, it seams the app was not publish to c:\app folder. The app send "Hello World" to STDOUT.
Here the dockerfile:
#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
#For more information, please see https://aka.ms/containercompat
FROM mcr.microsoft.com/dotnet/core/runtime:3.0-nanoserver-1903 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/core/sdk:3.0-nanoserver-1903 AS build
WORKDIR /src
COPY ["dotnetCore3.csproj", "./"]
RUN dotnet restore "dotnetCore3.csproj"
COPY . .
WORKDIR "/src/"
RUN dotnet build "dotnetCore3.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "dotnetCore3.csproj" -c Release -o /app/publish
docker-compose.yml:
version: '3.4'
services:
dotnetcore3:
image: *****/myregistry/dotnetcore3
build:
context: .
dockerfile: Dockerfile
Running:
docker run *****/myregistry/dotnetcore3:dev
run the shell from inside the docker instead of running the app. Using the shell, i see there is nothing at c:\app folder.
Here the full log from Container tools window:
========== Preparing Containers ==========
Getting Docker containers ready...
docker-compose -f "C:\Users\MS20004\source\repos\dotnetCore3\docker-compose.yml" -f "C:\Users\MS20004\source\repos\dotnetCore3\docker-compose.override.yml" -f "C:\Users\MS20004\source\repos\dotnetCore3\obj\Docker\docker-compose.vs.debug.g.yml" -p dockercompose15898560444299855188 --no-ansi config
networks:
default:
external:
name: nat
services:
dotnetcore3:
build:
context: C:\Users\*****\source\repos\dotnetCore3
dockerfile: Dockerfile
labels:
com.microsoft.created-by: visual-studio
com.microsoft.visual-studio.project-name: dotnetCore3
target: base
entrypoint: cmd /c "set DISABLE_PERFORMANCE_DEBUGGER=1 & C:\\remote_debugger\\x64\\msvsmon.exe
/noauth /anyuser /silent /nostatus /noclrwarn /nosecuritywarn /nofirewallwarn
/nowowwarn /timeout:2147483646 /LogDebuggeeOutputToStdOut"
environment:
NUGET_FALLBACK_PACKAGES: c:\.nuget\fallbackpackages
NUGET_PACKAGES: C:\.nuget\packages
image: dotnetcore3:dev
labels:
com.microsoft.visualstudio.debuggee.arguments: ' --additionalProbingPath c:\.nuget\packages
--additionalProbingPath c:\.nuget\fallbackpackages "bin\Debug\netcoreapp3.0\dotnetCore3.dll"'
com.microsoft.visualstudio.debuggee.killprogram: C:\remote_debugger\x64\utils\KillProcess.exe
dotnet.exe
com.microsoft.visualstudio.debuggee.program: '"C:\Program Files\dotnet\dotnet.exe"'
com.microsoft.visualstudio.debuggee.workingdirectory: C:\app
volumes:
- C:\Users\*****\source\repos\dotnetCore3:C:\app:rw
- C:\Users\*****\onecoremsvsmon\16.3.0040.0:C:\remote_debugger:ro
- C:\Program Files\dotnet\sdk\NuGetFallbackFolder:c:\.nuget\fallbackpackages:ro
- C:\Users\*****\.nuget\packages:c:\.nuget\packages:ro
version: '3.4'
docker ps --filter "status=running" --format {{.ID}};{{.Names}}
docker-compose -f "C:\Users\*****\source\repos\dotnetCore3\docker-compose.yml" -f "C:\Users\*****\source\repos\dotnetCore3\docker-compose.override.yml" -f "C:\Users\*****\source\repos\dotnetCore3\obj\Docker\docker-compose.vs.debug.g.yml" -p dockercompose15898560444299855188 --no-ansi build
Building dotnetcore3
Step 1/4 : FROM mcr.microsoft.com/dotnet/core/runtime:3.0-nanoserver-1903 AS base
---> 279077ab63e3
Step 2/4 : WORKDIR /app
---> Using cache
---> 6ce0262ac12a
Step 3/4 : LABEL com.microsoft.created-by=visual-studio
---> Using cache
---> 3756662eccd6
Step 4/4 : LABEL com.microsoft.visual-studio.project-name=dotnetCore3
---> Using cache
---> 71d353776b98
Successfully built 71d353776b98
Successfully tagged dotnetcore3:dev
docker-compose -f "C:\Users\*****\source\repos\dotnetCore3\docker-compose.yml" -f "C:\Users\*****\source\repos\dotnetCore3\docker-compose.override.yml" -f "C:\Users\*****\source\repos\dotnetCore3\obj\Docker\docker-compose.vs.debug.g.yml" -p dockercompose15898560444299855188 --no-ansi up -d --no-build --force-recreate --remove-orphans
Creating dockercompose15898560444299855188_dotnetcore3_1 ...
Creating dockercompose15898560444299855188_dotnetcore3_1 ... done
Done! Docker containers are ready.
========== Preparing Containers ==========
Getting Docker containers ready...
docker-compose -f "C:\Users\*****\source\repos\dotnetCore3\docker-compose.yml" -f "C:\Users\*****\source\repos\dotnetCore3\docker-compose.override.yml" -f "C:\Users\*****\source\repos\dotnetCore3\obj\Docker\docker-compose.vs.debug.g.yml" -p dockercompose15898560444299855188 --no-ansi config
networks:
default:
external:
name: nat
services:
dotnetcore3:
build:
context: C:\Users\*****\source\repos\dotnetCore3
dockerfile: Dockerfile
labels:
com.microsoft.created-by: visual-studio
com.microsoft.visual-studio.project-name: dotnetCore3
target: base
entrypoint: cmd /c "set DISABLE_PERFORMANCE_DEBUGGER=1 & C:\\remote_debugger\\x64\\msvsmon.exe
/noauth /anyuser /silent /nostatus /noclrwarn /nosecuritywarn /nofirewallwarn
/nowowwarn /timeout:2147483646 /LogDebuggeeOutputToStdOut"
environment:
NUGET_FALLBACK_PACKAGES: c:\.nuget\fallbackpackages
NUGET_PACKAGES: C:\.nuget\packages
image: *****/dockerhub/dotnetcore3:dev
labels:
com.microsoft.visualstudio.debuggee.arguments: ' --additionalProbingPath c:\.nuget\packages
--additionalProbingPath c:\.nuget\fallbackpackages "bin\Debug\netcoreapp3.0\dotnetCore3.dll"'
com.microsoft.visualstudio.debuggee.killprogram: C:\remote_debugger\x64\utils\KillProcess.exe
dotnet.exe
com.microsoft.visualstudio.debuggee.program: '"C:\Program Files\dotnet\dotnet.exe"'
com.microsoft.visualstudio.debuggee.workingdirectory: C:\app
volumes:
- C:\Users\*****\source\repos\dotnetCore3:C:\app:rw
- C:\Users\*****\onecoremsvsmon\16.3.0040.0:C:\remote_debugger:ro
- C:\Program Files\dotnet\sdk\NuGetFallbackFolder:c:\.nuget\fallbackpackages:ro
- C:\Users\*****\.nuget\packages:c:\.nuget\packages:ro
version: '3.4'
docker ps --filter "status=running" --format {{.ID}};{{.Names}}
365e9e5b6bb8;dockercompose15898560444299855188_dotnetcore3_1
docker exec -i 365e9e5b6bb8 C:\remote_debugger\x64\utils\KillProcess.exe dotnet.exe
docker-compose -f "C:\Users\*****\source\repos\dotnetCore3\docker-compose.yml" -f "C:\Users\*****\source\repos\dotnetCore3\docker-compose.override.yml" -f "C:\Users\*****\source\repos\dotnetCore3\obj\Docker\docker-compose.vs.debug.g.yml" -p dockercompose15898560444299855188 --no-ansi build
Building dotnetcore3
Step 1/4 : FROM mcr.microsoft.com/dotnet/core/runtime:3.0-nanoserver-1903 AS base
---> 279077ab63e3
Step 2/4 : WORKDIR /app
---> Using cache
---> 6ce0262ac12a
Step 3/4 : LABEL com.microsoft.created-by=visual-studio
---> Using cache
---> 3756662eccd6
Step 4/4 : LABEL com.microsoft.visual-studio.project-name=dotnetCore3
---> Using cache
---> 71d353776b98
Successfully built 71d353776b98
Successfully tagged *****/myregistry/dotnetcore3:dev
docker-compose -f "C:\Users\*****\source\repos\dotnetCore3\docker-compose.yml" -f "C:\Users\*****\source\repos\dotnetCore3\docker-compose.override.yml" -f "C:\Users\*****\source\repos\dotnetCore3\obj\Docker\docker-compose.vs.debug.g.yml" -p dockercompose15898560444299855188 --no-ansi up -d --no-build --force-recreate --remove-orphans
Recreating dockercompose15898560444299855188_dotnetcore3_1 ...
Recreating dockercompose15898560444299855188_dotnetcore3_1 ... done
Done! Docker containers are ready.
========== Debugging ==========
docker ps --filter "status=running" --filter "name=dockercompose15898560444299855188_dotnetcore3_" --format {{.ID}} -n 1
54b4bc125895
docker inspect --format="{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}" 54b4bc125895
172.30.67.88
========== Debugging ==========
docker ps --filter "status=running" --filter "name=dockercompose15898560444299855188_dotnetcore3_" --format {{.ID}} -n 1
54b4bc125895
docker inspect --format="{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}" 54b4bc125895
172.30.67.88
========== Debugging ==========
docker ps --filter "status=running" --filter "name=dockercompose15898560444299855188_dotnetcore3_" --format {{.ID}} -n 1
314dff0ffdf6
docker inspect --format="{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}" 314dff0ffdf6
172.30.75.30
========== Debugging ==========
docker ps --filter "status=running" --filter "name=dockercompose15898560444299855188_dotnetcore3_" --format {{.ID}} -n 1
314dff0ffdf6
docker inspect --format="{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}" 314dff0ffdf6
172.30.75.30
Update:
I try to build it from docker CLI and found out that the proxy was blocking the access to internet from the container. I don't know if is why the build fails inside visual studio. The log shows no errors but also i can't see any output from dotnet commands.
Upvotes: 1
Views: 399
Reputation: 15103
The solution was to modify dockerfile in order to get the app pre-compiled into the build, instead of building from the container.
Here the final DockerFile:
FROM mcr.microsoft.com/dotnet/core/runtime:3.0-nanoserver-1903 AS base
WORKDIR /app
COPY ".\bin\Release\netcoreapp3.0" "/app"
#just for debug purposes
RUN dir
FROM base AS final
ENTRYPOINT ["dotnet", "dotnetCore3.dll"]
Upvotes: 1