无法通过 docker-sdk golang 连接到 Docker 守护程序

Docker 正在运行,创建了一个容器,但返回:无法连接到 unix 上的 Docker 守护程序:///var/run/docker.sock 作为响应。Docker 守护程序是否正在运行?ContainerExecCreateContainerExecAttach


可能是什么问题。


import (

    "archive/tar"

    "bytes"

    "context"

    "fmt"

    "io"

    "io/ioutil"

    "log"

    "net"

    "os"

    "strconv"

    "strings"

    "time"


    client "docker.io/go-docker"

    "docker.io/go-docker/api/types"

    "docker.io/go-docker/api/types/container"

    "docker.io/go-docker/api/types/network"

    "docker.io/go-docker/api/types/swarm"

    "docker.io/go-docker/api/types/volume"

    "github.com/containerd/containerd/reference"

    "github.com/play-with-docker/play-with-docker/config"

)


func (d *docker) ExecAttach(instanceName string, command []string, out io.Writer) (int, error) {

    e, err := d.c.ContainerExecCreate(context.Background(), instanceName, types.ExecConfig{Cmd: command, AttachStdout: true, AttachStderr: true, Tty: true})

    if err != nil {

        return 0, err

    }

    resp, err := d.c.ContainerExecAttach(context.Background(), e.ID, types.ExecConfig{AttachStdout: true, AttachStderr: true, Tty: true})

    if err != nil {

        return 0, err

    }

}


qq_笑_17
浏览 144回答 1
1回答

白板的微信

看起来很正常。可能取决于调用时 Docker 的状态。可以通过Ping检查docker或仅等待一秒钟。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go