Docker Community Forums

Share and learn in the Docker community.

Can't access docker socket with `docker exec`

docker

(Steve Azzopardi) #1

Hello,

So I am trying to use DinD official imagine and following the instructions from https://hub.docker.com/_/docker/ so running the commands below work perfelectly

docker run --privileged --name some-docker -d docker:stable-dind
docker run --rm --link some-docker:docker docker:edge info

As soon as I want to run the run command in detached mode and then exec in the container I the error it can not connect to socket

docker run --privileged --name some-docker -d docker:stable-dind
docker run --rm -t -d --link  some-docker:docker docker:edge
docker exec -it $CONTAINER_ID sh -c "docker info"
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Am I missing something as of why exec command can’t access the socket? Is the link ignored when you exec into a container?

docker version

Client:
 Version:           18.06.1-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        e68fc7a
 Built:             Tue Aug 21 17:21:31 2018
 OS/Arch:           darwin/amd64
 Experimental:      false

Server:
 Engine:
  Version:          18.06.1-ce
  API version:      1.38 (minimum version 1.12)
  Go version:       go1.10.3
  Git commit:       e68fc7a
  Built:            Tue Aug 21 17:29:02 2018
  OS/Arch:          linux/amd64
  Experimental:     true

(Steve Azzopardi) #2

This was DOCKER_HOST environment variables is missing when you run docker exec so the correct command is the following

docker exec -e DOCKER_HOST=tcp://docker:2375 -it $CONTAINER_ID sh -c "docker info"