如何让Docker工具箱与.net Core 2.0项目一起使用 [英] How to get docker toolbox to work with .net core 2.0 project

查看:78
本文介绍了如何让Docker工具箱与.net Core 2.0项目一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在.NET Core 2.0项目中使用Docker功能时遇到错误.我收到一条错误消息,说

I'm getting an error trying to use the Docker functionality with my .NET core 2.0 project. I've been getting an error message saying

Visual Studio容器工具要求Docker必须先运行 构建,调试或运行容器化项目.有关更多信息, 请参阅: http://aka.ms/DockerToolsTroubleshooting

Visual Studio Container Tools requires Docker to be running before building, debugging or running a containerized project. For more info, please see: http://aka.ms/DockerToolsTroubleshooting

我点击了链接,并意识到我拥有Windows 10 Home x64,并且不得不安装Docker Toolbox,而不是Docker For Windows.现在,它安装了名为

I followed the link, and upon realizing I have Windows 10 Home x64, and had to install Docker Toolbox, instead of Docker For Windows. Now it installed this executable called

Docker快速入门终端

Docker Quickstart Terminal

这是启动docker服务的一种方式吗?我试过运行此可执行文件,它似乎正在工作.我的容器正在运行,但是Visual Studio容器工具的错误仍然存​​在.

Is this the way one is supposed to start up that docker services? I have tried running this executable, and it seems to be working. My containers are running, but the error for Visual Studio Container Tools still persists.

我想念什么?为了在Visual Studio 2017中使用Docker容器支持,是否需要Windows版本高于Home版本?

What am I missing? Is having a version of windows higher than Home required in order to use the Docker Container Support within Visual Studio 2017?

更新:

我试图遵循Quetzcoatl的建议,但在Visual Studio中,我仍然对这些工具遇到同样的错误.这是我在Docker快速入门终端中运行的内容.在Visual Studio成功打开项目后,我尝试构建项目,但仍然遇到上述关于容器工具的错误.

I tried to follow Quetzcoatl's suggestion, and I am still getting the same error within visual studio about those tools. Here is what I ran in the Docker Quick Start Terminal. I tried building the project after Visual Studio successfully opened the project, and was still getting the aforementioned error regarding the container tools.

我的devenv.exe文件位于

My devenv.exe file is located at

C:\ Program Files(x86)\ Microsoft Visual Studio \ 2017 \ Community \ Common7 \ IDE \ devenv.exe

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\devenv.exe

我的解决方案文件位于

D:\ Development \ Visual Studio \ Musify2 \ Musify2 \ Musify2.sln

D:\Development\Visual Studio\Musify2\Musify2\Musify2.sln

更新2:

我运行了一些建议的命令以在docker quickstart终端中尝试,这是这些命令的结果quetz

I ran some of the suggested commands to try in the docker quickstart terminal and here were the results of those commands quetz

推荐答案

使用Docker Toolbox有点棘手,但实际上core-2.0与此处无关.一切都与docker,docker-toolbox和VS有关.

With Docker Toolbox that's a little tricky, but actually the core-2.0 has nothing to do here. It's all about docker, docker-toolbox, and VS.

首先:

这是启动docker服务的一种方式吗?我已经尝试运行此可执行文件,并且似乎正在运行.

Is this the way one is supposed to start up that docker services? I have tried running this executable, and it seems to be working.

是的.如果docker机器/服务正在运行-很好!

Yes it is. If docker machine/services are running - that's good!

现在,您必须意识到,在docker中,通常,有关docker运行方式/位置的信息保存在环境变量中. quickstart脚本不仅为您启动了docker-machine并检查了一些基本内容,还设置了一些环境变量,以便以后所有dockerdocker-compose等命令都知道在哪里寻找docker.虚拟机.在您的情况下,信息主要由VM的IP和Docker侦听的端口号组成.

Now, you have to realize that in docker, typically, the information about how/where the docker is running is kept in environment variables. The quickstart script not only starts the docker-machine for you and checks some basic things, it also sets up a couple of environmental variables so that later all commands like docker, docker-compose etc know where to look for the docker virtual machine. In your/our case that information mainly consists of an IP of the VM and a port number that Docker listens on.

..,而您的Visual Studio对此一无所知,因为我敢打赌,您已经从StartMenu或桌面"图标或通过双击解决方案文件运行了VisualStudio,因此它没有机会获得quickstart控制台中的环境变量.

.. and your Visual Studio has no knowledge of that, because, I bet on that, you have ran the VisualStudio from StartMenu or from Desktop icon or by double-clicking on a solution file, so it had no chance of getting the environmental variables from quickstart console.

解决方案非常简单:确保VS获得该信息.也就是说,请确保获取环境变量,请确保获取环境变量的新鲜状态,因为IP/端口有时会发生波动.因此,不要将它们复制到您的OS设置中,因为不会自动刷新它们.

The solution is quite simple: make sure that VS gets that information. That is, make sure it gets that environmental variables, and make sure that it gets the fresh state of them, because the IP/port may fluctuate sometimes. So don't just copy them to your OS settings, because nothing will ever automagically refresh them..

我发现的最简单的方法是仅关闭Visual Studio,运行docker工具箱快速入门控制台,然后从该控制台中运行VisualStudio ,例如,对于我的VS2017 Community Edition:

The simplest way I found is to just close Visual Studio, run docker toolbox quickstart console, then run the VisualStudio from within that console, for example, for my VS2017 Community Edition:

Starting "default"...
(default) Check network to re-create if needed...
(default) Waiting for an IP...
(.......snip..........)


                        ##         .
                  ## ## ##        ==
               ## ## ## ## ##    ===
           /"""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~
           \______ o           __/
             \    \         __/
              \____\_______/

docker is configured to use the default machine with IP 192.168.99.100
For help getting started, check out the docs at https://docs.docker.com

Start interactive shell
quetzalcoatl@LAP049 MINGW32 ~
$ /c/Program\ Files\ \(x86\)/Microsoft\ Visual\ Studio/2017/Community/Common7/IDE/devenv.exe C:\\PATH\\TO\\MY\\SOLUTION.sln

即使使用TAB完成,该路径也很长,因此通常创建一个很小的.sh脚本来为我运行该脚本.

The path is pretty long to write, even with TAB-completion, so usually make a tiny .sh script to run that for me.

顺便说一句!请注意,到达DEVENV的路径必须是类unix(/c/Program\ Files...),因为mingw shell必须了解这一点,而到SOLUTION的路径则必须是普通的Windows路径(c:\projects\foo\bar\..),因为VisualStudio将尝试在读取之后启动.

BTW! Notice that the path to DEVENV must be unix-like (/c/Program\ Files...), because the mingw shell has to understand that, while the path to SOLUTION must be a normal windows path (c:\projects\foo\bar\..) because VisualStudio will try to read that after starting up.

这篇关于如何让Docker工具箱与.net Core 2.0项目一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆