Expose a Unix socket to the host system from inside from a Docker container

I would like to run aweb server inside a Docker container that listens to a Unix socket, instead of to a port. I'm finding a lot of results on sharing the Docker socket, but I don't think that's what I want.

I want the host system to be able to connect to the Unix socket that's being listened to inside the container.

I'm using docker-compose, so the usual way of using -v doesn't work.

My ngix site config:

server {                                                                                             
   listen 80; listen [::]:80;                                                            
    server_name foo.com www.foo.com;

    location / {                                                                         
        proxy_pass http://unix:/var/lib/docker/volumes/app_shared/_data/app.https.sock:;       
        proxy_set_header Host $http_host;                                                            
        proxy_http_version 1.1;                                                                      
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;                                 
        proxy_set_header X-Forwarded-Proto https;                                                    
    } 

docker-compose.yml

version: '3'
services:      
  web:
    build: .
    volumes:
            - shared:/var/app
    command: "npm start"
volumes:
   shared:

Yet it says I can't connect to the socket, even though it exists at this location on the host.

You can communicate the host machine or even two containers using the same socket. In the general case of two containers, you should start the two dockers from the host machine sharing a volume that should be created in the host machine.

docker run --name "containerA" -v /var/run/common_socket_dir:/var/run/common_socket_dir...
docker run --name "containerB" -v /var/run/common_socket_dir:/var/run/common_socket_dir...

Both, containerA and containerB can now use sockets as /var/run/common_socket_dir/socketX to interconnect. Of course, the host machine could use the sockets in this volume to communicate with containers