Мне недавно пришлось обновить docker (2.2.0.0 stable 42247), и теперь у меня возникают проблемы с запуском dotnet watch
в docker контейнере с использованием docker-compose
.
Мой рабочий процесс заключается в монтировании каталога решения (на хосте) в контейнер docker, который запускает dotnet watch
в соответствующем проекте, первоначальная версия выглядела примерно так:
./docker-compose.yml
version: "3.2"
services:
my-api:
build:
context: $MY_API_LOCATION_ON_HOST # the folder with the .sln file and all projects
dockerfile: $DOCKERFILE_ROOT/Dockerfile-aspcore-dev
args:
PROJECT: app/src/MyApi # Where the .csproj will be
volumes:
- type: bind
source: $MY_API_LOCATION_ON_HOST # the folder with the .sln file and all projects
target: /app
- type: bind
source: $SECRETS_FOLDER # C:\Users\DevUser\AppData\Roaming\Microsoft\UserSecrets
target: /root/.microsoft/usersecrets
./Dockerfile-aspcore-dev
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS base
ARG PROJECT
WORKDIR ${PROJECT}
ENTRYPOINT ["dotnet", "watch", "run", "--urls", "http://0.0.0.0:5000"]
, и он будет успешно работать. После обновления я получаю следующую ошибку:
docker-compose up --build --force-recreate my-api
Building my-api
Step 1/4 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS base
---> 2fe8fe202baf
Step 2/4 : ARG PROJECT
---> Using cache
---> cee4bd05745b
Step 3/4 : WORKDIR ${PROJECT}
---> Using cache
---> ed12fa68fc7e
Step 4/4 : ENTRYPOINT ["dotnet", "watch", "run", "--urls", "http://0.0.0.0:5000"]
---> Using cache
---> 6c0b8b95cd8e
Successfully built 6c0b8b95cd8e
Successfully tagged src_my-api:latest
Recreating src_my-api_1 ... done
Attaching to src_my-api_1
my-api_1 | System.IO.FileNotFoundException: Unable to find the specified file.
my-api_1 | at Interop.Sys.GetCwdHelper(Byte* ptr, Int32 bufferSize)
my-api_1 | at Interop.Sys.GetCwd()
my-api_1 | at System.Environment.get_CurrentDirectory()
my-api_1 | at System.IO.Directory.GetCurrentDirectory()
my-api_1 | at Microsoft.DotNet.CommandFactory.CommandResolver.TryResolveCommandSpec(ICommandResolverPolicy
commandResolverPolicy, String commandName, IEnumerable`1 args, NuGetFramework framework, String configuration, String outputPath,
String applicationName)
my-api_1 | at Microsoft.DotNet.CommandFactory.CommandFactoryUsingResolver.Create(ICommandResolverPolicy commandResolverPolicy, String commandName, IEnumerable`1 args, NuGetFramework framework, String configuration, String outputPath, String applicationName)
my-api_1 | at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
my-api_1 | at Microsoft.DotNet.Cli.Program.Main(String[] args)
src_my-api_1 exited with code 1
Этот вывод вместе с моим временным обходным решением предполагает, что это связано с неспособностью выяснить, что такое cwd или pwd, а не проблема с tnet смотреть. Обход выглядит так:
./docker-compose.yml
version: "3.2"
services:
my-api:
+ tty: true
+ stdin_open: true
working_dir: /app/src/MyApi # Where the .csproj will be
build:
context: $MY_API_LOCATION_ON_HOST
dockerfile: $DOCKERFILE_ROOT/Dockerfile-aspcore-dev
volumes:
- type: bind
source: $MY_API_LOCATION_ON_HOST # the folder with the .sln file and all projects
target: /app
- type: bind
source: $SECRETS_FOLDER # C:\Users\DevUser\AppData\Roaming\Microsoft\UserSecrets
target: /root/.microsoft/usersecrets
./Dockerfile-aspcore-dev
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS base
ARG PROJECT
WORKDIR ${PROJECT}
- ENTRYPOINT ["dotnet", "watch", "run", "--urls", "http://0.0.0.0:5000"]
run:
docker-compose up --build --force-recreate search-api
Building search-api
Step 1/3 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS base
---> 2fe8fe202baf
Step 2/3 : ARG PROJECT
---> Using cache
---> cee4bd05745b
Step 3/3 : WORKDIR ${PROJECT}
---> Using cache
---> ed12fa68fc7e
Successfully built ed12fa68fc7e
Successfully tagged src_search-api:latest
Recreating src_search-api_1 ... done
Attaching to src_search-api_1
затем запустите :
docker exec -it src_my-api_1 dotnet "watch" "run" "--urls" "http://0.0.0.0:5000"
watch : Polling file watcher is enabled
watch : Started
watch : Exited
watch : File changed: /app/src/MyApi/Constants.cs
watch : Started
...
дополнительно выполнение чего-то вроде
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS base
ARG PROJECT
WORKDIR ${PROJECT}
ENTRYPOINT ["dotnet", "fsx"]
приведет к очень похожей ошибке
docker-compose up --build --force-recreate my-api
Building my-api
Step 1/4 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS base
---> 2fe8fe202baf
Step 2/4 : ARG PROJECT
---> Using cache
---> cee4bd05745b
Step 3/4 : WORKDIR ${PROJECT}
---> Using cache
---> ed12fa68fc7e
Step 4/4 : ENTRYPOINT ["dotnet", "fsx"]
---> Running in eaa49fc2294c
Removing intermediate container eaa49fc2294c
---> f2f4f212d0e9
Successfully built f2f4f212d0e9
Successfully tagged src_my-api:latest
Recreating src_my-api_1 ... done
Attaching to src_my-api_1
my-api_1 | System.IO.FileNotFoundException: Unable to find the specified file.
my-api_1 | at Interop.Sys.GetCwdHelper(Byte* ptr, Int32 bufferSize)
my-api_1 | at Interop.Sys.GetCwd()
my-api_1 | at System.Environment.get_CurrentDirectory()
my-api_1 | at System.IO.Directory.GetCurrentDirectory()
my-api_1 | at Microsoft.DotNet.CommandFactory.CommandResolver.TryResolveCommandSpec(ICommandResolverPolicy
commandResolverPolicy, String commandName, IEnumerable`1 args, NuGetFramework framework, String configuration, String outputPath,
String applicationName)
my-api_1 | at Microsoft.DotNet.CommandFactory.CommandFactoryUsingResolver.Create(ICommandResolverPolicy commandResolverPolicy, String commandName, IEnumerable`1 args, NuGetFramework framework, String configuration, String outputPath, String applicationName)
my-api_1 | at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
my-api_1 | at Microsoft.DotNet.Cli.Program.Main(String[] args)
src_my-api_1 exited with code 1