Reputation: 1409
I have asp core api project and i am using visual studio 2017 to run my project. After i renamed the docker container that was previously created using visual studio using this command on command line,
docker rename CONTAINER NEW_NAME
I receive the following message when i try to run the project again in visual studio.
Thanks for the help
Can not find docker container with the name starting with 'previous_container_name'.
Upvotes: 18
Views: 24003
Reputation: 41
I had a similar error message ("Cannot find container to attach, check if the container is running or not").
In my case I upgraded my project from net6 to net8 and after that the error occurred.
What didn't help:
What did help:
Upvotes: 0
Reputation: 1
If your project uses Launch profiles to run, I fixed this with the following steps:
Upvotes: 0
Reputation: 1727
In my case, I had both the "image" section and the "build" section in my docker-compose.yml. I just removed the build section because I wanted it to pull an image from the docker registry, and now it is working.
Upvotes: 0
Reputation: 4539
In my case i have tried all of those but solution is very simple in V.S. 2019
Before all there is a bugfix packet for visual studio 2017 even if you using 19 beta, for this on https://visualstudio.microsoft.com/vs/ Download and install that pocket.
For automatically composing also you should add Docker Compose Support follow this link https://learn.microsoft.com/tr-tr/dotnet/standard/containerized-lifecycle-architecture/design-develop-containerized-apps/visual-studio-tools-for-docker
1-) Right click to targeted project root folder on solution explorer that contains Dockerfile and select add-> Docker Support it will ask you its always contains would you like to create new one? Click yes. It will create new Dockerfile.
You will see some changes in new Dockerfile like your project changes or nuget package changes affectness
2-) Right click the newly replaced Dockerfile and Build Image. It will successfully build
3-) Choose debugger as Docker instead IIS Express vs. Even don't use other debugger while developing project if you do not need
Upvotes: 1
Reputation: 13339
One more cause is using solution folders for your docker project and a version of Visual Studio 2017 less than 15.9, upgrading to 15.9+ fixed this for me, see this issue.
Upvotes: 0
Reputation: 27027
This happened for me because I stopped a container manually via the commandline, then Visual Studio got confused.
To get round the issue I simply added a single ' ' space character to docker-compose.yml and saved the file. This forced Visual Studio to restart the container and connect to it.
I'm sure starting/stopping Visual Studio would also have worked, but the whitespace change was nice and fast.
Upvotes: 3
Reputation: 95
I also have the similar problem. These steps always help me to solve the issues. Solution 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.
Solution 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.
if anybody could find a constant solution please also let us know.
Upvotes: 2
Reputation: 193
I had a similar problem, and it was caused because I started Docker after opening the project. VS does some things with Docker on opening of the project, and will fail if Docker is not started.
Lesson learned: make sure Docker is running before starting Visual Studio. If Docker is not started, then start Docker, close your solution, and re-open it.
VS will re-create the container as it opens the project.
Upvotes: 4
Reputation: 2781
This error started happening to me when someone on the team unchecked the build checkbox for the docker-compose project. Make sure it is enabled in Build -> Configuration Manager
Upvotes: 18
Reputation: 9218
Delete the .vs
folder in your solution directory (close the solution first), the Docker image name seems to be cached somewhere in there.
Upvotes: 39