1

Docker is running, ContainerExecCreate creates a container, but ContainerExecAttach returns: Cannot connect to the Docker daemon at unix: ///var/run/docker.sock in response. Is the docker daemon running?

What could be the problem.

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
    }
}
fabelx
  • 197
  • 1
  • 12
  • 2
    Can you run other `docker` commands? Are you running this program on the host, or in a container? (And do you _need_ to programmatically run a `docker exec`?) – David Maze Jun 01 '21 at 14:52
  • 1
    Yes, only programmatically. Dockerd works fine, I use docker sdk for python all the time and everything works fine. – fabelx Jun 01 '21 at 18:47

1 Answers1

1

It looks normal. May depend on the state of the docker at the time of the call. It is possible to check docker via Ping or just wait one second.

nefrasdum
  • 26
  • 2