Never change the permission of your mounted socket file inside the container! It will be changed on the host too.
You can use socat as root forward a tcp socket to a unix socket. This is how I did it: httpd24-docker-image/local-builder.yml at d8f6807ee454b42ed11b044e5e84da3af0bf5372 · itsziget/httpd24-docker-image · GitHub
version: "3.7"
services:
socat:
image: alpine/socat
command: tcp-listen:2375,fork,reuseaddr unix-connect:/var/run/docker.sock
user: root
volumes:
- type: bind
source: /var/run/docker.sock
target: /var/run/docker.sock
network_mode: host
ci:
depends_on:
- socat
build:
dockerfile: local-builder.Dockerfile
context: .
environment:
DOCKER_HOST: localhost:2375
network_mode: host
I used the host network but it should work without it setting DOCKER_HOST to the right value.