'Dind in docker-compose connection reset by peer

I am trying connect to docker deamon in docker(dind). I use docker-compose to run dind and docker-client. When I try to connect to dind from docker-client. It gives an error. What might be the solution for that ?

enter image description here

version: '3'
services:
  docker:
    # Starts a Docker daemon at the DNS name "docker"
    # Note:
    #  * This must be called "docker" to line up with the default
    #    TLS certificate name
    #  * DOCKER_TLS_CERTDIR defaults to "/certs
    image: docker:dind
    privileged: yes
    volumes:
      - certs:/certs/client
  docker-client:
    # Provides a Docker client container, including the client
    # certs generated by the docker:dind container, above.
    # Notes:
    #  * The name of this container doesn't matter
    #  * The DOCKER_CERT_PATH defaults to /certs/client, the
    #    same path where the docker:dind image generates the
    #    client certificate (and that we've mounted inside this
    #    container).
    # You can execute a shell inside this container by running:
    #   docker-compose exec docker-client sh
    image: docker
    command: sh -c 'while [ 1 ]; do sleep 1000; done'
    environment:
      DOCKER_HOST: tcp://docker:2376
    volumes:
      - certs:/certs/client
volumes:
  certs:


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source