2016-10-03 17 views
1

私はGoでプロジェクトを作成していますが、 "github.com/docker/docker/client"と "github.com/docker/docker/api/types"の両方を使用していますが、私が試してみて、私は次のエラーを取得するコンテナを作成するとき:golangドッカーエンジンでコンテナを作成するとエラーが発生する

ERROR: 2016/10/03 22:39:26 containers.go:84: error during connect: Post https://%2Fvar%2Frun%2Fdocker.sock/v1.23/containers/create : http: server gave HTTP response to HTTPS client

私はこれが起こっている理由を理解することはできませんし、それが唯一の(旧「github.com/docker/新しいgolang]ドッキングウィンドウのエンジンを使用した後に起こりましたengine-api "は廃止予定です)。

コードは何も複雑ではないので、私は何か欠けていた場合、私は疑問に思う:

resp, err := cli.Pcli.ContainerCreate(context.Background(), initConfig(), nil, nil, "") 
    if err != nil { 
      return err 
    } 

と呼ばれるinitConfigを行い、次もここに

func initConfig() (config *container.Config) { 
    mount := map[string]struct{}{"/root/host": {}} 
    return &container.Config{Image: "leadis_image", Volumes: mount, Cmd: strslice.StrSlice{"/root/server.py"}, AttachStdout: true}} 

は私dockerfileです

FROM debian

MAINTAINER Leadis Journey

LABEL Description="This docker image is used to compile and execute user's program."

LABEL Version="0.1"

VOLUME /root/host/

RUN apt-get update && yes | apt-get upgrade

RUN yes | apt-get install gcc g++ python3 make

COPY container.py /root/server.py

EDIT

ただ単純にプログラム

package main 

import (
     "fmt" 
     "os" 
     "io/ioutil" 
     "github.com/docker/docker/client" 
     "github.com/docker/docker/api/types" 
     "github.com/docker/docker/api/types/container" 
     "github.com/docker/docker/api/types/strslice" 
     "golang.org/x/net/context" 
) 


func initConfig() (config *container.Config) { 
     mount := map[string]struct{}{"/root/host": {}} 
     return &container.Config{Image: "leadis_image", Volumes: mount, Cmd: strslice.StrSlice{"/root/server.py"}, AttachStdout: true} 
} 

func main() { 
     client, _ := client.NewEnvClient() 


     cwd, _ := os.Getwd() 
     ctx, err := os.Open(cwd+"/Dockerfile.tar.gz") 
     if err != nil { 
       fmt.Println(err) 
       return 
     } 
     build, err := client.ImageBuild(context.Background(), ctx, types.ImageBuildOptions{Tags: []string{"leadis_image"}, Context: ctx, SuppressOutput: false}) 
     if err != nil { 
       fmt.Println(err) 
       return 
     } 

     b, _ := ioutil.ReadAll(build.Body) 
     fmt.Println(string(b)) 
     _, err = client.ContainerCreate(context.Background(), initConfig(), nil, nil, "") 
     if err != nil { 
       fmt.Println(err) 
     } 
} 

同じdockerfileでそれをテストしようとしたが、私はまだ同じエラーを取得:

error during connect: Post https://%2Fvar%2Frun%2Fdocker.sock/v1.23/containers/create : http: server gave HTTP response to HTTPS client

+0

プロジェクトにhttpsが有効になっているようですが、あなたのローカルドッカーデーモンはまだプレーンhttpになっています。たぶんこのドキュメントはhttps://docs.docker.com/engine/security/https/に役立つかもしれません –

+0

ドッカーインスタンスに渡すコマンドラインオプションは何ですか? ( 'ps -ef | grep docker'あなたの'/etc/docker/daemon.json'には何が入っていますか?curl --unix-socket /var/run/docker.sock http:/ v1に対する標準的な応答を得ますか? .23/containers/json?all = 1' – Matt

答えて

0
client.NewEnvClient() 

私が試した最後の時間を、このAPIは、環境を期待します通常のドッカークライアントとは異なる構文のDOCKER_HOSTのような変数です。 client.goから

// NewEnvClient initializes a new API client based on environment variables. 
// Use DOCKER_HOST to set the url to the docker server. 
// Use DOCKER_API_VERSION to set the version of the API to reach, leave empty for latest. 
// Use DOCKER_CERT_PATH to load the TLS certificates from. 
// Use DOCKER_TLS_VERIFY to enable or disable TLS verification, off by default. 

これを使用するには、これらのいずれかの形式でエクスポート/設定するDOCKER_HOSTが必要:

  1. UNIX:/// VAR /実行/ドッカ。靴下
  2. http://localhost:2375
  3. https://localhost:2376
関連する問題