それぞれ異なるゴランサービスを実行する2つのコンテナを取得しようとしています。どちらのサービスもnet/http
パッケージで構築されています。私は、APIフロントエンドと認証サービスバックエンドを持っています。私はリンクが、私はping auth
とcurl -X Post http://auth:8080/validate
しかしgolang以内に、私はdial address tcp i/o timeout
得ることができるAPIコンテナから作業しているので、知っているGolang MicroservicesはMac用Dockerを使用して通信できません
version: "2"
services:
staticfiles:
build: ./files
volumes:
- /public
- /views
api:
build: ./api
environment:
- PORT=8080
- BASE_URL=https://example.org
- AUTH_HOST=auth
- AUTH_PORT=8080
- VIEW_DIR=/views
- PUBLIC_DIR=/public
ports:
- "80:8080"
volumes_from:
- staticfiles:ro
links:
- auth
depends_on:
- staticfiles
db:
build: ./postgres
environment:
- POSTGRES_USER=inheritor
- POSTGRES_DB=inheritor
auth:
build: ./auth
expose:
- "8080"
environment:
- PORT=8080
- DB_USER=inheritor
- DB_NAME=inheritor
- DB_HOST=db
- DB_Port=5432
links:
- db
:
は、ここに私のコンファイルです。ここにゴランのコードがあります。
var (
authString = "http://" + env.AuthHost + ":" + env.AuthPort
)
//ValidateToken validates a token using the session in DB
func ValidateToken(req *model.ValidateRequest) (*model.JWTClaims, error) {
client := new(http.Client)
api := authString + "/validate"
cont, err := model.Jsonify(req)
if err != nil {
return nil, exception.NewInternalError("Could not turn the request into a json object.")
}
request, err := http.NewRequest("POST", api, bytes.NewBuffer(cont))
if err != nil {
return nil, exception.NewInternalError("Could not create request: " + err.Error())
}
request.Header.Set("Content-type", "application/json")
response, err := client.Do(request)
if err != nil {
return nil, exception.NewInternalError("Could not make the request: " + err.Error())
}
defer response.Body.Close()
res := new(model.AuthResponse)
res.Claims = new(model.JWTClaims)
decoder := json.NewDecoder(response.Body)
err = decoder.Decode(&res)
spew.Dump(response.Body)
if err != nil {
return nil, exception.NewInternalError("Could not parse response back from auth service. " + err.Error())
}
if response.StatusCode != http.StatusOK {
return nil, exception.NewInvalidJWTError(res.Error)
}
return res.Claims, nil
}
client.Do(request)
は、ダイヤルエラーを投げているものです。私が来ているすべてのリクエストをスクリーニングするために出力するロガーを持っているので、今私の認証サービスであっても触れられていない。
env.AuthHost
AUTH_HOST
環境変数にマッピングされています。env.AuthPort
は、環境変数Auth_PORT
にマップされます。
大変助かりました。
私がMacOSXを実行している場合に役立ちます。だから私はgolang内net.LookupHost(env.AuthHost)
を実行し、それがその後ping
、curl
、さらには異なるIPアドレスを返して
:
FROM golang:1.6
RUN mkdir -p /go/src/github.com/dixonwille/Inheritor/api
WORKDIR /go/src/github.com/dixonwille/Inheritor/api
COPY . /go/src/github.com/dixonwille/Inheritor/api
RUN go build -v -o Inheritor cmd/Inheritor/main.go
USER nobody
ENTRYPOINT ["./Inheritor"]
EDIT:
Client:
Version: 1.12.0-rc4
API version: 1.24
Go version: go1.6.2
Git commit: e4a0dbc
Built: Wed Jul 13 03:28:51 2016
OS/Arch: darwin/amd64
Experimental: true
Server:
Version: 1.12.0-rc4
API version: 1.24
Go version: go1.6.2
Git commit: e4a0dbc
Built: Wed Jul 13 03:28:51 2016
OS/Arch: linux/amd64
Experimental: true
どちらgolangs Dockerfile
は次のようになりますdocker inspect
。これはゴラン事ですか?
EDIT:種類の日が経つにつれてデバッグしようとしているすべての編集のための
申し訳ありません。
authString
のポート部分を削除すると、要求は処理されますが、応答の解析時にエラーが発生します。応答はNGINXの301リダイレクトです。これは私のスタック内にさえないので、私は奇妙だと思います。リダイレクトの場所ヘッダーはlocalhost
です。これは奇妙なものだと思います。
私はホストマシン上のポートを公開し、そのポートでより良い運(同じホスト名)でアクセスしようとしました。
EDIT:
だから、私が仮定マック唯一のものです。私はレポをクローンダウンしてWindows 10で動かし、私は私の認証サービスに接続することができました。これはMac用のDockerエラーですか?私はおそらくそれを彼らに報告するつもりですが、Macユーザーにとってまだ問題であるため、私はこれを閉じたとは考えていません。
私はクライアントとは思っていません。再試行するには、grpcサーバーがオンラインになる可能性を高めるためにダイヤルする前に 'time.Sleep(10 * time.Second)'を追加してみてください。 'links:-db'を' depends_on:-db'に置き換えることもできます – Plato
呼び出しが助けになるまでに10秒を追加する方法はありませんか?これは一定のエラーです。毎回このメソッドを試して同じエラーが発生するたびに、コンテナは再起動しません。私はリンクを必要としないので、私はIPアドレスを保持することができますか? – Clemsonopoly94