我创造了围棋的一个项目,我同时使用“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
我不明白为什么发生这种情况,并使用新golang泊坞窗引擎(旧的“github.com/docker/后只发生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
编辑
只是试图用一个简单的程序
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
看起来您的项目已启用https,但您的本地docker守护程序仍然处于纯http状态。也许这个文档有助于https://docs.docker.com/engine/security/https/ –
你传递给你的docker实例的命令行选项是什么? ('PS英法| grep的docker'在'/等/泊坞窗/ daemon.json'你得到一个'卷曲--unix插座标准响应/var/run/docker.sock HTTP什么:/ V1? 0.23 /集装箱/ JSON?所有= 1' – Matt