我有asp核心api项目,我使用visual studio 2017来运行我的项目。 我在命令行上使用此命令重命名之前使用visual studio创建的docker容器
docker rename CONTAINER NEW_NAME
当我尝试在visual studio中再次运行项目时收到以下消息。
感谢您的帮助
Can not find docker container with the name starting with 'previous_container_name'.
答案 0 :(得分:7)
删除解决方案目录中的.vs
文件夹(首先关闭解决方案),Docker镜像名称似乎缓存在那里的某处。
答案 1 :(得分:5)
答案 2 :(得分:1)
我有一个类似的问题,这是由于打开项目后启动Docker引起的。 VS在项目打开时对Docker做一些事情,如果未启动Docker,它将失败。
经验教训:在启动Visual Studio之前,请确保Docker正在运行。如果未启动Docker,请启动Docker,关闭您的解决方案,然后重新打开它。
VS将在打开项目时重新创建容器。
答案 3 :(得分:0)
我也有类似的问题。 这些步骤始终可以帮助我解决问题。 解决方案1:
1- Close VS
2- delete obj folder of root solution folder.
3- delete obj folder of all projects which are involved in docker-compose file.(example all APIs)
4- Open VS
5- Remove the docker-compose project from solution and add it again.
During the creation process, don't overwrite the old files with new ones, to prevent deletion of you current docker-compose.yml configuration.
解决方案2:
On the first time of container creation, copy the creation command:
example: docker-compose -f "[path]\docker-compose.yml" -f "[path]\docker-compose.override.yml" -f "[path]\docker-compose.vs.debug.g.yml" -p dockercompose17926074389345686639 --no-ansi up -d --no-build --force-recreate --remove-orphans
any time there is an error just run this command manually.
如果有人可以找到一个不变的解决方案,也请告知我们。
答案 4 :(得分:0)
发生这种情况是因为我通过命令行手动停止了一个容器,然后Visual Studio感到困惑。
要解决该问题,我仅向docker-compose.yml添加了一个''空格字符并保存了文件。这迫使Visual Studio重新启动容器并连接到它。
我敢肯定,启动/停止Visual Studio也是可以的,但是空格的更改非常方便快捷。
答案 5 :(得分:0)
另一个原因是为您的docker项目使用了解决方案文件夹,而Visual Studio 2017的版本低于15.9,升级到15.9+修复了该问题,请参见this issue。
答案 6 :(得分:0)
就我而言,我已经尝试了所有这些方法,但是在 V.S。中,解决方案非常简单。 2019
在所有https://visualstudio.microsoft.com/vs/上,即使有使用19 beta的版本,Visual Studio 2017仍然存在一个错误修正包 下载并安装该口袋。
对于自动撰写,您还应该添加 Docker Compose支持,点击此链接https://docs.microsoft.com/tr-tr/dotnet/standard/containerized-lifecycle-architecture/design-develop-containerized-apps/visual-studio-tools-for-docker
1-)右键单击包含Dockerfile的解决方案资源管理器上的目标项目根文件夹,然后选择add-> Docker Support,它将询问您是否始终包含您要创建一个新文件?单击是。它将创建新的 Dockerfile 。
您将在新的 Dockerfile 中看到一些更改,例如项目更改或nuget软件包更改的影响程度
2-)右键单击新替换的 Dockerfile 和构建映像。 它将成功构建
3-)选择调试器作为Docker而不是IIS Express,甚至不需要开发项目时就不要使用其他调试器