问题描述
我在尝试将 Docker 功能用于我的 .NET core 2.0 项目时遇到错误.我收到一条错误消息,说
<块引用>Visual Studio 容器工具需要先运行 Docker构建、调试或运行容器化项目.如需更多信息,请参阅:
更新 2:
我在 docker quickstart 终端中运行了一些建议的命令来尝试,这里是这些命令的结果 quetz
用 Docker Toolbox 有点棘手,但实际上 core-2.0 与这里无关.都是关于 docker、docker-toolbox 和 VS 的.
首先:
<块引用>这是启动 docker 服务的方式吗?我试过运行这个可执行文件,它似乎可以工作.
是的.如果 docker 机器/服务正在运行 - 那很好!
现在,您必须意识到,在 docker 中,有关 docker 运行方式/位置的信息通常保存在环境变量中.quickstart
脚本不仅为你启动 docker-machine 并检查一些基本的东西,它还设置了几个环境变量,以便以后所有的命令,如 docker
,docker-compose
等知道在哪里寻找 docker 虚拟机.在您/我们的案例中,该信息主要由 VM 的 IP 和 Docker 侦听的端口号组成.
.. 而您的 Visual Studio 对此一无所知,因为我敢打赌,您已经从 StartMenu 或桌面图标或双击解决方案文件运行了 VisualStudio,因此它没有机会获得quickstart
控制台中的环境变量.
解决方案非常简单:确保 VS 获取该信息.也就是说,确保它获得环境变量,并确保它获得它们的新鲜状态,因为 IP/端口有时可能会波动.所以不要只是将它们复制到您的操作系统设置中,因为没有任何东西会自动刷新它们..
我发现最简单的方法是关闭 Visual Studio,运行 docker toolbox 快速启动控制台,然后从该控制台中运行 VisualStudio,例如,对于我的 VS2017 社区版:
开始默认"...(默认)如果需要,检查网络以重新创建...(默认)等待 IP...(.......剪断............)## .## ## ## ==## ## ## ## ## ===/"""""""""""""""""\___/===~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~/===- ~~~\______ o __/ __/\____\___/docker 配置为使用 IP 为 192.168.99.100 的默认机器如需入门帮助,请查看 https://docs.docker.com 上的文档启动交互式外壳quetzalcoatl@LAP049 MINGW32 ~$/c/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/devenv.exe C:\PATH\TO\MY\SOLUTION.sln
即使使用 TAB 完成,路径也很长,所以通常制作一个小的 .sh
脚本来为我运行它.
顺便说一句!请注意,DEVENV 的路径必须是类 unix (/c/Program Files...
),因为 mingw shell 必须理解这一点,而 SOLUTION 的路径必须是普通的 windows 路径(c:projectsfooar..
) 因为 VisualStudio 会在启动后尝试读取它.
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 Container Tools requires Docker to be running before building, debugging or running a containerized project. For more info, please see: http://aka.ms/DockerToolsTroubleshooting
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 Quickstart Terminal
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.
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?
UPDATE:
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.
My devenv.exe file is located at
C:Program Files (x86)Microsoft Visual Studio2017CommunityCommon7IDEdevenv.exe
and my solution file is located at
D:DevelopmentVisual StudioMusify2Musify2Musify2.sln
UPDATE 2:
I ran some of the suggested commands to try in the docker quickstart terminal and here were the results of those commands quetz
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.
First of all:
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.
Yes it is. If docker machine/services are running - that's good!
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.
.. 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.
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..
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
The path is pretty long to write, even with TAB-completion, so usually make a tiny .sh
script to run that for me.
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:projectsfooar..
) because VisualStudio will try to read that after starting up.
这篇关于如何让 docker 工具箱与 .net core 2.0 项目一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!