The Wayback Machine - https://web.archive.org/web/20161006035207/http://stackoverflow.com/questions/39840235/error-when-creating-container-with-golang-docker-engine
Join the Stack Overflow Community
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am creating a project in Go and I am using both "github.com/docker/docker/client" and "github.com/docker/docker/api/types", but when I try and create a container I get the following error:

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

I can't understand why this is happening and it only happened after using the new golang docker engine(the old "github.com/docker/engine-api" is now deprecated).

The code isn't anything complicated, so I wonder if I am missing something:

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

And the initConfig that is called does the following:

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}} 

Also here is my 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

Just tried to test it with a simpler program

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) } 

Same dockerfile, but I still get the same error:

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

share|improve this question
    
Looks like your project is enabled https, but your local docker daemon still in plain http. Maybe this doc helps docs.docker.com/engine/security/https – Haoming Zhang2 days ago
    
What are the command line options you pass to your docker instance? (ps -ef | grep docker What's in your /etc/docker/daemon.json? Do you get a standard response to a curl --unix-socket /var/run/docker.sock http:/v1.23/containers/json?all=1 – Matt2 days ago

Browse other questions tagged or ask your own question.

close