2016-07-28 9 views
6

それぞれ異なるゴランサービスを実行する2つのコンテナを取得しようとしています。どちらのサービスもnet/httpパッケージで構築されています。私は、APIフロントエンドと認証サービスバックエンドを持っています。私はリンクが、私はping authcurl -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.AuthHostAUTH_HOST環境変数にマッピングされています。
  • env.AuthPortは、環境変数Auth_PORTにマップされます。

大変助かりました。

私がMacOSXを実行している場合に役立ちます。だから私はgolang内net.LookupHost(env.AuthHost)を実行し、それがその後pingcurl、さらには異なる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ユーザーにとってまだ問題であるため、私はこれを閉じたとは考えていません。

+0

私はクライアントとは思っていません。再試行するには、grpcサーバーがオンラインになる可能性を高めるためにダイヤルする前に 'time.Sleep(10 * time.Second)'を追加してみてください。 'links:-db'を' depends_on:-db'に置き換えることもできます – Plato

+0

呼び出しが助けになるまでに10秒を追加する方法はありませんか?これは一定のエラーです。毎回このメソッドを試して同じエラーが発生するたびに、コンテナは再起動しません。私はリンクを必要としないので、私はIPアドレスを保持することができますか? – Clemsonopoly94

答えて

1

Mac用Dockerは、今日新しいベータ版をリリースしました。これは接続に関する私の問題を修正したようです。今私は自分のWindows PC上で動作することが分かったときにソースコードを変更しました。ここで

は修正のためのドッカーのバージョンである:

Client: 
Version:  1.12.0 
API version: 1.24 
Go version: go1.6.3 
Git commit: 8eab29e 
Built:  Thu Jul 28 21:04:48 2016 
OS/Arch:  darwin/amd64 
Experimental: true 

Server: 
Version:  1.12.0 
API version: 1.24 
Go version: go1.6.3 
Git commit: 8eab29e 
Built:  Thu Jul 28 21:04:48 2016 
OS/Arch:  linux/amd64 
Experimental: true 

そしてここでは、コンファイルです:

version: "2" 
services: 
    staticfiles: 
    build: ./files 
    volumes: 
     - /public 
     - /views 
     - /migrations 
    databasefiles: 
    build: ./databasefiles 
    volumes: 
     - /var/lib/postgresql/data 
    db: 
    build: ./postgres 
    depends_on: 
     - databasefiles 
    volumes_from: 
     - databasefiles 
    environment: 
     - POSTGRES_USER=inheritor 
     - POSTGRES_DB=inheritor 
    auth: 
    build: ./auth 
    expose: 
     - "8080" 
    depends_on: 
     - staticfiles 
    volumes_from: 
     - staticfiles:ro 
    environment: 
     - PORT=8080 
     - DB_USER=inheritor 
     - DB_NAME=inheritor 
     - DB_HOST=db 
     - DB_PORT=5432 
     - MIGRATION_DIR=/migrations 
    links: 
     - db 
    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 

私の周りのサービスを移動しましたが、私は変化するであろう別の何も表示されません。コンテナ間の通信。これはちょうどここに他の人が同じ問題を抱えている。

関連する問題