Recently, I encountered an issue while working on a project that involved PowerShell and Docker. The error message was:
Waiting for CM to become available...
Invoke-RestMethod : Unable to connect to the remote server
At C:\Projects\Project.Web\up.ps1:121 char:19
+ ... $status = Invoke-RestMethod "http://localhost:8079/api/http/routers ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Fix - Issue got fix with below steps
This error indicated that my PowerShell script could not connect to the server at http://localhost:8079/api/http/routers, which was crucial for the project's functionality. After some investigation, I discovered that the problem was related to the Docker network configuration.
Here is how I resolved the issue:
Step-by-Step Solution
List Docker Networks:
First, I needed to identify the existing Docker networks. This can be done using the following command:
docker network ls
This command lists all the networks created by Docker. The output should look something like this:
NETWORK ID NAME DRIVER SCOPE
9b73baa9dff4 bridge bridge local
2c2b1a85c1a2 host host local
3e8e8a1c32b4 none null local
7e8f1b1d3f44 my_project_network bridge local
Remove the Project Network:
After identifying the network associated with my project, I removed it using the following command:
docker network rm <name_of_network>
For example, if the network name was my_project_network, the command would be:
docker network rm my_project_network
Run the up.psl script again
If you have any further questions or run into additional issues, feel free to leave a comment or reach out. Happy coding!