2つのDockerコンテナがあります。AWS-ECS - コンテナ間の通信 - 不明なホストエラー
- TestWeb(公開:80)
- TestAPI(公開:80)
Testweb容器はTestApiコンテナを呼び出します。ホストは8080ポートからTestWebコンテナと通信できます。ホストは8081を使用してTestApiと通信できます。
私の開発ボックス(Windows 10)でTestApiを呼び出すことができますが、AWS(ECS) "不明なホスト"例外。両方の容器はうまく動作し、私はそれらを個別に呼び出すことができます。私は内部的にcontainer2のメソッドへのHttpClientを使用して、残りの呼び出しを行うメソッドを呼び出すときしかし、それはエラーを与える:
An error occurred while sending the request. ---> System.Net.Http.CurlException: Couldn't resolve host name.
コード:
using (var client = new HttpClient())
{
try
{
string url = "http://testapi/api/Tenant/?i=" + id;
var response = client.GetAsync(url).Result;
if (response.IsSuccessStatusCode)
{
var responseContent = response.Content;
string responseString = responseContent.ReadAsStringAsync().Result;
return responseString;
}
return response.StatusCode.ToString();
}
catch (HttpRequestException httpRequestException)
{
return httpRequestException.Message;
}
}
次は私がしようとしているものです。
2つのコンテナ(TestWeb、TestAPI)は、AWS ECSの同じタスク定義にあります。コンテナを調べると、各コンテナのIPアドレスが取得されます。私はIPアドレスでcontainer1からcontainer2にpingできます。しかし、私はcontainer2の名前を使用してpingすることはできません。それは私に "不明なホスト"エラーを与える。