首先,我正在学习如何从命令行使用Docker。
然后,想看看我能用Visual Studio做些什么。
我的目标是使用Visual Studio 2017创建ASP.NET Core Web API并使用容器开发,调试,测试和部署该Web API。
该解决方案有两个项目:一个是通常的ASP.NET Core项目,另一个是名为Docker Compose的项目:
正如您所看到的,它与您在任何其他ASP.NET Core应用程序中可以看到的相同的Program.cs和Startup.cs,相同类型的控制器,因此没有任何内容。 C#代码,它知道有关Docker或容器的任何信息或它将要进入的操作环境。
Docker唯一关于这个特定项目的事情是Docker文件的存在(你可以看到它在图像中打开,并附有构建另一个图像的说明)。
特定图像将成为Linux映像。所以,我需要做的一件事是转到Docker菜单并切换到Linux容器:
重现问题的步骤
预期行为
应用程序运行并允许其调试。
实际行为
由于错误导致构建失败:
1>------ Build started: Project: docker-compose, Configuration: Debug Any CPU ------
1>docker-compose -f "C:\Users\tiagoperes\Documents\Visual Studio 2017\Projects\PsWebApi\docker-compose.yml" -f "C:\Users\tiagoperes\Documents\Visual Studio 2017\Projects\PsWebApi\docker-compose.override.yml" -f "C:\Users\tiagoperes\Documents\Visual Studio 2017\Projects\PsWebApi\docker-compose.vs.debug.yml" -p dockercompose1712142422 config
1>services:
1> pswebapi:
1> build:
1> args:
1> source: obj/Docker/empty/
1> context: C:\Users\tiagoperes\Documents\Visual Studio 2017\Projects\PsWebApi\PsWebApi
1> dockerfile: Dockerfile
1> entrypoint: tail -f /dev/null
1> environment:
1> ASPNETCORE_ENVIRONMENT: Development
1> DOTNET_USE_POLLING_FILE_WATCHER: '1'
1> image: pswebapi:dev
1> labels:
1> com.microsoft.visualstudio.targetoperatingsystem: linux
1> ports:
1> - 80/tcp
1> volumes:
1> - C:\Users\tiagoperes\Documents\Visual Studio 2017\Projects\PsWebApi\PsWebApi:/app:rw
1> - C:\Users\tiagoperes\clrdbg:/clrdbg:ro
1> - C:\Users\tiagoperes\.nuget\packages:/root/.nuget/packages:ro
1>version: '2.0'
1>docker ps --filter "status=running" --filter "name=dockercompose1712142422_pswebapi_" --format {{.ID}} -n 1
1>PsWebApi -> C:\Users\tiagoperes\Documents\Visual Studio 2017\Projects\PsWebApi\PsWebApi\bin\Debug\netcoreapp1.1\PsWebApi.dll
1>C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -NoProfile -WindowStyle Hidden -ExecutionPolicy RemoteSigned -File "C:\Users\tiagoperes\AppData\Local\Temp\GetVsDbg.ps1" -Version vs2017u1 -RuntimeID debian.8-x64 -InstallPath "C:\Users\tiagoperes\clrdbg\vsdbg"
1>Info: Using vsdbg version '15.1.10630.1'
1>Info: Using Runtime ID 'linux-x64'
1>Info: Latest version of VsDbg is present. Skipping downloads
1>docker-compose -f "C:\Users\tiagoperes\Documents\Visual Studio 2017\Projects\PsWebApi\docker-compose.yml" -f "C:\Users\tiagoperes\Documents\Visual Studio 2017\Projects\PsWebApi\docker-compose.override.yml" -f "C:\Users\tiagoperes\Documents\Visual Studio 2017\Projects\PsWebApi\docker-compose.vs.release.yml" -p dockercompose1712142422 kill
1>docker-compose -f "C:\Users\tiagoperes\Documents\Visual Studio 2017\Projects\PsWebApi\docker-compose.yml" -f "C:\Users\tiagoperes\Documents\Visual Studio 2017\Projects\PsWebApi\docker-compose.override.yml" -f "C:\Users\tiagoperes\Documents\Visual Studio 2017\Projects\PsWebApi\docker-compose.vs.release.yml" -p dockercompose1712142422 down --rmi local --remove-orphans
1>Removing dockercompose1712142422_pswebapi_1 ...
1>[1A[2K
1>Removing dockercompose1712142422_pswebapi_1 ... [32mdone[0m
1>[1BRemoving network dockercompose1712142422_default
1>docker-compose -f "C:\Users\tiagoperes\Documents\Visual Studio 2017\Projects\PsWebApi\docker-compose.yml" -f "C:\Users\tiagoperes\Documents\Visual Studio 2017\Projects\PsWebApi\docker-compose.override.yml" -f "C:\Users\tiagoperes\Documents\Visual Studio 2017\Projects\PsWebApi\docker-compose.vs.debug.yml" -p dockercompose1712142422 kill
1>docker-compose -f "C:\Users\tiagoperes\Documents\Visual Studio 2017\Projects\PsWebApi\docker-compose.yml" -f "C:\Users\tiagoperes\Documents\Visual Studio 2017\Projects\PsWebApi\docker-compose.override.yml" -f "C:\Users\tiagoperes\Documents\Visual Studio 2017\Projects\PsWebApi\docker-compose.vs.debug.yml" -p dockercompose1712142422 down --rmi local --remove-orphans
1>Removing network dockercompose1712142422_default
1>Network dockercompose1712142422_default not found.
1>docker-compose -f "C:\Users\tiagoperes\Documents\Visual Studio 2017\Projects\PsWebApi\docker-compose.yml" -f "C:\Users\tiagoperes\Documents\Visual Studio 2017\Projects\PsWebApi\docker-compose.override.yml" -f "C:\Users\tiagoperes\Documents\Visual Studio 2017\Projects\PsWebApi\docker-compose.vs.debug.yml" -p dockercompose1712142422 up -d --build
1>Creating network "dockercompose1712142422_default" with the default driver
1>Building pswebapi
1>Step 1/6 : FROM microsoft/aspnetcore:1.1
1> ---> c87149836213
1>Step 2/6 : ARG source
1> ---> Using cache
1> ---> f48760163a33
1>Step 3/6 : WORKDIR /app
1> ---> Using cache
1> ---> cb7ee352c5c5
1>Step 4/6 : EXPOSE 80
1> ---> Using cache
1> ---> fc3d1d4fcfb5
1>Step 5/6 : COPY ${source:-obj/Docker/publish} .
1> ---> Using cache
1> ---> b6ef96f437c0
1>Step 6/6 : ENTRYPOINT dotnet PsWebApi.dll
1> ---> Using cache
1> ---> 0fdc28e1982b
1>Successfully built 0fdc28e1982b
1>Successfully tagged pswebapi:dev
1>Creating dockercompose1712142422_pswebapi_1 ...
1>Creating dockercompose1712142422_pswebapi_1
1>[1A[2K
1>Creating dockercompose1712142422_pswebapi_1 ... [31merror[0m
1>[1B
1>ERROR: for dockercompose1712142422_pswebapi_1 Cannot start service pswebapi: oci runtime error: container_linux.go:262: starting container process caused "process_linux.go:339: container init caused \"rootfs_linux.go:57: mounting \\\"/C/Users/tiagoperes/Documents/Visual Studio 2017/Projects/PsWebApi/PsWebApi\\\" to rootfs \\\"/var/lib/docker/overlay2/318ea1b0b7d0bbc13e75c543448338e655d825f58c41a88c5ca7d03680a16fac/merged\\\" at \\\"/app\\\" caused \\\"stat /C/Users/tiagoperes/Documents/Visual Studio 2017/Projects/PsWebApi/PsWebApi: host is down\\\"\""
1>ERROR: for pswebapi Cannot start service pswebapi: oci runtime error: container_linux.go:262: starting container process caused "process_linux.go:339: container init caused \"rootfs_linux.go:57: mounting \\\"/C/Users/tiagoperes/Documents/Visual Studio 2017/Projects/PsWebApi/PsWebApi\\\" to rootfs \\\"/var/lib/docker/overlay2/318ea1b0b7d0bbc13e75c543448338e655d825f58c41a88c5ca7d03680a16fac/merged\\\" at \\\"/app\\\" caused \\\"stat /C/Users/tiagoperes/Documents/Visual Studio 2017/Projects/PsWebApi/PsWebApi: host is down\\\"\""
1>Encountered errors while bringing up the project.
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: The "PrepareForLaunch" task failed unexpectedly.
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: Microsoft.DotNet.Docker.CommandLineClientException: Creating network "dockercompose1712142422_default" with the default driver
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: Building pswebapi
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: Creating dockercompose1712142422_pswebapi_1 ...
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: Creating dockercompose1712142422_pswebapi_1
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: [1A[2K
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: Creating dockercompose1712142422_pswebapi_1 ... [31merror[0m
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: [1B
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: ERROR: for dockercompose1712142422_pswebapi_1 Cannot start service pswebapi: oci runtime error: container_linux.go:262: starting container process caused "process_linux.go:339: container init caused \"rootfs_linux.go:57: mounting \\\"/C/Users/tiagoperes/Documents/Visual Studio 2017/Projects/PsWebApi/PsWebApi\\\" to rootfs \\\"/var/lib/docker/overlay2/318ea1b0b7d0bbc13e75c543448338e655d825f58c41a88c5ca7d03680a16fac/merged\\\" at \\\"/app\\\" caused \\\"stat /C/Users/tiagoperes/Documents/Visual Studio 2017/Projects/PsWebApi/PsWebApi: host is down\\\"\""
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: ERROR: for pswebapi Cannot start service pswebapi: oci runtime error: container_linux.go:262: starting container process caused "process_linux.go:339: container init caused \"rootfs_linux.go:57: mounting \\\"/C/Users/tiagoperes/Documents/Visual Studio 2017/Projects/PsWebApi/PsWebApi\\\" to rootfs \\\"/var/lib/docker/overlay2/318ea1b0b7d0bbc13e75c543448338e655d825f58c41a88c5ca7d03680a16fac/merged\\\" at \\\"/app\\\" caused \\\"stat /C/Users/tiagoperes/Documents/Visual Studio 2017/Projects/PsWebApi/PsWebApi: host is down\\\"\""
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: Encountered errors while bringing up the project..
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018:
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: For more troubleshooting information, go to http://aka.ms/DockerToolsTroubleshooting ---> Microsoft.DotNet.Docker.CommandLineClientException: Creating network "dockercompose1712142422_default" with the default driver
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: Building pswebapi
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: Creating dockercompose1712142422_pswebapi_1 ...
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: Creating dockercompose1712142422_pswebapi_1
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: [1A[2K
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: Creating dockercompose1712142422_pswebapi_1 ... [31merror[0m
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: [1B
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: ERROR: for dockercompose1712142422_pswebapi_1 Cannot start service pswebapi: oci runtime error: container_linux.go:262: starting container process caused "process_linux.go:339: container init caused \"rootfs_linux.go:57: mounting \\\"/C/Users/tiagoperes/Documents/Visual Studio 2017/Projects/PsWebApi/PsWebApi\\\" to rootfs \\\"/var/lib/docker/overlay2/318ea1b0b7d0bbc13e75c543448338e655d825f58c41a88c5ca7d03680a16fac/merged\\\" at \\\"/app\\\" caused \\\"stat /C/Users/tiagoperes/Documents/Visual Studio 2017/Projects/PsWebApi/PsWebApi: host is down\\\"\""
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: ERROR: for pswebapi Cannot start service pswebapi: oci runtime error: container_linux.go:262: starting container process caused "process_linux.go:339: container init caused \"rootfs_linux.go:57: mounting \\\"/C/Users/tiagoperes/Documents/Visual Studio 2017/Projects/PsWebApi/PsWebApi\\\" to rootfs \\\"/var/lib/docker/overlay2/318ea1b0b7d0bbc13e75c543448338e655d825f58c41a88c5ca7d03680a16fac/merged\\\" at \\\"/app\\\" caused \\\"stat /C/Users/tiagoperes/Documents/Visual Studio 2017/Projects/PsWebApi/PsWebApi: host is down\\\"\""
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: Encountered errors while bringing up the project.
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: at Microsoft.DotNet.Docker.DockerComposeClient.<ExecuteAsync>d__18.MoveNext()
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: --- End of inner exception stack trace ---
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: at Microsoft.DotNet.Docker.DockerComposeClient.<ExecuteAsync>d__18.MoveNext()
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: --- End of stack trace from previous location where exception was thrown ---
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: at Microsoft.DotNet.Docker.DockerWorkspace.<PrepareForLaunchAsync>d__14.MoveNext()
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: --- End of stack trace from previous location where exception was thrown ---
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: at Microsoft.DotNet.Docker.BuildTasks.DockerBaseTask.Execute()
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Docker\Microsoft.VisualStudio.Docker.Compose.targets(192,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
1>Done building project "docker-compose.dcproj" -- FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
其他信息
操作系统:Windows 10
答案 0 :(得分:1)
我遇到了类似的问题。
这就是你如何解决它。
Windows Power-Shell并运行以下命令:
docker ps -a
你能看到什么吗?
重置&gt;重置为出厂默认值
然后,登录。
转到Windows Power-Shell运行以下命令:
netstat -an | findstr:445
TCP 0.0.0.0:445 0.0.0.0:0 LISTENING
TCP 10.0.75.1:445 10.0.75.1:50609 ESTABLISHE
TCP 10.0.75.1:50609 10.0.75.1:445 ESTABLISHE
TCP [::]:445 [::]:0 LISTENING
windows firewall - how yours should look like
检查具有高级安全性的Windows防火墙,看看是否有任何规则阻止与端口445,tcp和udp的连接。如果是,并且已启用,请通过右键单击并选择禁用来禁用。
转到文件资源管理器并测试您是否可以访问:
\\ 10.0.75.1 \ C
我的一些朋友报告了以下问题:
https://docs.docker.com/docker-for-windows/#firewall-rules-for-shared-drives
但是如果你到目前为止一直遵循所有步骤,那么你应该没有任何问题。
希望这可以帮到你。
答案 1 :(得分:0)
1>ERROR: for pswebapi Cannot start service pswebapi: oci runtime error: container_linux.go:262: starting container process caused "process_linux.go:339: container init caused \"rootfs_linux.go:57: mounting \\\"/C/Users/tiagoperes/Documents/Visual Studio 2017/Projects/PsWebApi/PsWebApi\\\" to rootfs \\\"/var/lib/docker/overlay2/318ea1b0b7d0bbc13e75c543448338e655d825f58c41a88c5ca7d03680a16fac/merged\\\" at \\\"/app\\\" caused \\\"stat /C/Users/tiagoperes/Documents/Visual Studio 2017/Projects/PsWebApi/PsWebApi: host is down\\\"\""
这是docker守护程序中共享驱动器的问题。确保在docker设置中的共享驱动器下,勾选了C驱动器,然后重新启动docker守护程序。
这些共享驱动器链接将您的本地文件系统转发到托管docker守护程序的计算机,并且没有它们正常工作,docker无法从主机系统进行任何卷安装。