yusing / go-proxy

Easy to use reverse proxy with docker integration
MIT License
137 stars 7 forks source link

no matching route for subdomain - docker containers #6

Closed earvingad closed 6 months ago

earvingad commented 6 months ago

compose:

version: '3'
services:
  hello_world:
    image: prakhar1989/static-site
    container_name: hello # => whoami.y.z
    labels:
      - proxy.aliases=hello
    ports:
      - 81:80 # http
  app:
    build: .
    container_name: go-proxy
    restart: always
    networks: # ^also add here
      - default
    environment:
      # - GOPROXY_DEBUG=1 # (optional, enable only for debug)
      - GOPROXY_REDIRECT_HTTP=0 # (optional, uncomment to disable http redirect (http -> https))
    ports:
      - 80:80 # http
      # - 443:443 # optional, https
      - 8080:8080 # http panel
      # - 8443:8443 # optional, https panel

      # optional, if you declared any tcp/udp proxy, set a range you want to use
      # - 20000:20100/tcp
      # - 20000:20100/udp
    volumes:
      # use existing certificate
      # - /path/to/cert.pem:/app/certs/cert.crt:ro
      # - /path/to/privkey.pem:/app/certs/priv.key:ro

      # use autocert feature
      # - ./certs:/app/certs

      # if local docker provider is used (by default)
      - /var/run/docker.sock:/var/run/docker.sock:ro

      # to use custom config and providers
      - ./config:/app/config
    dns:
      - 127.0.0.1 # workaround for "lookup: no such host"
    extra_hosts:
      # required if you use local docker provider and have containers in `host` network_mode
      - host.docker.internal:host-gateway
    logging:
      driver: 'json-file'
      options:
        max-file: '1'
        max-size: 128k

networks: # ^you may add other external networks
  default:
    driver: bridge

Config file content:

providers:
  eee:
    kind: file
    value: eee.yml

Provider eee.yml:

eee: # matching `app1.y.z` -> http://x.y.z
  host: eee.neon.lan
  port: 8000

Panel is working and accessible, hello container is detected but with bad healt: screenshot-537x269

from inside go-proxy container (ip: 172.27.0.2) the hello contained ip (172.27.0.3) is reachable.

/app # ping 172.27.0.3
PING 172.27.0.3 (172.27.0.3): 56 data bytes
64 bytes from 172.27.0.3: seq=0 ttl=64 time=0.182 ms
64 bytes from 172.27.0.3: seq=1 ttl=64 time=0.157 ms

hello container can be accessed through 10.1.1.240:81 screenshot-450x321 And adding a manual provider entry does work, however this should be the automated behavior expected with docker container to avoid manual entries.

log result when running curl http://hello.neon.lan:

ERRO[03-28 21:53:06] "HEAD go-proxy:80/":
request failed
  - "go-proxy:80":
  no matching route for subdomain
DEBU[03-28 21:53:07] request URL: hello.neon.lan/                  alias=hello component=http_proxy path= path_mode=
DEBU[03-28 21:53:07] request headers: map[Accept:[*/*] User-Agent:[curl/8.6.0]]  alias=hello component=http_proxy path= path_mode=
INFO[03-28 21:53:07] http: proxy error: dial tcp 172.27.0.3:81: connect: connection refused  component=http_proxy

Hello container is running and subdomain matches container name and alias. Additionally Firewall is disabled, so I dont know what is wrong.

yusing commented 6 months ago

Config file content:

providers:
  eee:
    kind: file
    value: eee.yml

There is no docker provider in your config, please add this part back to your config file

local:
    kind: docker
    # for value format, see https://docs.docker.com/reference/cli/dockerd/
    value: FROM_ENV

into:

providers:
  eee:
    kind: file
    value: eee.yml
  local:
    kind: docker
    # for value format, see https://docs.docker.com/reference/cli/dockerd/
    value: FROM_ENV
yusing commented 6 months ago

modify the value if you have docker running in other machine

yusing commented 6 months ago
ports:
  - 81:80 # http
  1. you don't need this line most of the time, because in the image should already expose port 80

Panel is working and accessible, hello container is detected but with bad healt: screenshot-537x269

  1. you are pointing to port 81, which is the port on the host, not the port of the container (81:80)
earvingad commented 6 months ago

I have added:

local:
    kind: docker
    # for value format, see https://docs.docker.com/reference/cli/dockerd/
    value: FROM_ENV

And still can't get it to work, if I don't specify the ports: section for the container, then go-proxy wont recognize the container exists.

Already tested with adguardhome container, needed to specify ports: -3000:3000 or go-proxy wouldnt detect it.

This create a conflict with any container that uses any port of which go-proxy uses: 80. 8080, 443 and 8443.

Withouth specify ports:

go-proxy  | WARN[03-29 05:38:21] invalid autocert config
go-proxy  | - no domains specified
go-proxy  | - no provider specified
go-proxy  | - no email specified
go-proxy  | - unknown provider:  component=autocert
go-proxy  | INFO[03-29 05:38:21] starting http proxy server on :80 
go-proxy  | INFO[03-29 05:38:21] starting http panel server on :8080
go-proxy  | INFO[03-29 05:38:21] loaded 2 proxy configurations                 component=provider kind=file name=eee
go-proxy  | INFO[03-29 05:38:21] loaded 1 proxy configurations                 component=provider kind=docker name=local

screenshot-552x360

specifying Ports:

go-proxy  | WARN[03-29 05:42:37] invalid autocert config
go-proxy  | - no domains specified
go-proxy  | - no provider specified
go-proxy  | - no email specified
go-proxy  | - unknown provider:  component=autocert
go-proxy  | INFO[03-29 05:42:37] starting http proxy server on :80 
go-proxy  | INFO[03-29 05:42:37] starting http panel server on :8080
go-proxy  | INFO[03-29 05:42:37] loaded 2 proxy configurations                 component=provider kind=file name=eee
go-proxy  | INFO[03-29 05:42:37] loaded 2 proxy configurations                 component=provider kind=docker name=local

screenshot-493x308

yusing commented 6 months ago

Somehow I messed up the port selection function so I won't work starting from 0.4. Now fixed

yusing commented 6 months ago

The expected behaviour is: port - host:container is needed, only when network_mode: host is set otherwise, use exposed ports (already declared in Dockerfile of the image most of the time) or explicity specify

expose:
- 3000

For adguardhome, those are unnecessary as the latest commit fixed.

earvingad commented 6 months ago

Yes, now it is working fine!

In the case of adguardhome, port 3000 is just used once during first setup and if not explicitly set the webui at port 3000, the default will be changed to port 80 and webui wont be accessible. As long as you set up webui port to 3000 during first adguardhome set up, everything will be fine.

Finally, to allow DNS querys, port 53 UDP must declared in adguardhome compose block (this is just if anyone have an issue with it):

Adg:
   ....
   Ports:
     - 53:53/udp

Everything is working fine! thanks for the support!

yusing commented 6 months ago

Yes, now it is working fine!

In the case of adguardhome, port 3000 is just used once during first setup and if not explicitly set the webui at port 3000, the default will be changed to port 80 and webui wont be accessible. As long as you set up webui port to 3000 during first adguardhome set up, everything will be fine.

Finally, to allow DNS querys, port 53 UDP must declared in adguardhome compose block (this is just if anyone have an issue with it):

Adg:
   ....
   Ports:
     - 53:53/udp

Everything is working fine! thanks for the support!

I think you should either map port to host, or use reverse proxy, but not both.

Could you try this for example?

adg:
  image: ...
  restart: always
  # no "ports:"
  labels:
    - proxy.aliases=adg,adg-setup,adg-dns
    - proxy.adg.port=80
    - proxy.adg-setup.port=3000
    - proxy.adg-dns.scheme=udp
    - proxy.adg-dns.port=20000:53 # go-proxy listening on 20000/udp, then forward request to port 53

then in go-proxy:

go-proxy:
  ...
  ports:
  ...
  - 53:20000/udp # map go-proxy port 20000/udp to host port 53

Finally, set your dns to go-proxy's ip (your case 10.0.1.240? I forgot)

earvingad commented 6 months ago

Hello, port seems mapped when adding labels, both adg and adg-setup subdomains work, but the forward request does not seem to work. screenshot-517x463

dig ads.google.com @adg.neon.lan
;; communications error to 10.1.1.240#53: timed out
;; communications error to 10.1.1.240#53: timed out
;; communications error to 10.1.1.240#53: timed out

; <<>> DiG 9.18.24 <<>> ads.google.com @adg.neon.lan
;; global options: +cmd
;; no servers could be reached

Ports:

sudo ss -tulpn                                                                                                      
Netid  State   Recv-Q  Send-Q                       Local Address:Port     Peer Address:Port  Process
udp    UNCONN  0       0                                  0.0.0.0:53            0.0.0.0:*      users:(("docker-proxy",pid=27392,fd=4))
udp    UNCONN  0       0                                     [::]:53               [::]:*      users:(("docker-proxy",pid=27399,fd=4))
tcp    LISTEN  0       4096                               0.0.0.0:8080          0.0.0.0:*      users:(("docker-proxy",pid=27335,fd=4))
tcp    LISTEN  0       4096                               0.0.0.0:80            0.0.0.0:*      users:(("docker-proxy",pid=27371,fd=4))
tcp    LISTEN  0       4096                             127.0.0.1:41463         0.0.0.0:*      users:(("containerd",pid=2896,fd=10))
tcp    LISTEN  0       4096                                  [::]:8080             [::]:*      users:(("docker-proxy",pid=27345,fd=4))
tcp    LISTEN  0       4096                                  [::]:80               [::]:*      users:(("docker-proxy",pid=27377,fd=4))
go-proxy  | INFO[03-30 16:05:38] loaded 5 proxy configurations                 component=provider kind=docker name=local
go-proxy  | INFO[03-30 16:05:38] listening on udp:20000                        alias=adg-dns component=stream
go-proxy  | runtime: goroutine stack exceeds 1000000000-byte limit
go-proxy  | runtime: sp=0xc020590390 stack=[0xc020590000, 0xc040590000]
go-proxy  | fatal error: stack overflow
go-proxy  |
go-proxy  | runtime stack:
go-proxy  | runtime.throw({0xd4397a?, 0x1?})
go-proxy  |     /usr/local/go/src/runtime/panic.go:1023 +0x5c fp=0xc00009be18 sp=0xc00009bde8 pc=0x43b85c
go-proxy  | runtime.newstack()
go-proxy  |     /usr/local/go/src/runtime/stack.go:1103 +0x5bd fp=0xc00009bfc8 sp=0xc00009be18 pc=0x456e1d
go-proxy  | runtime.morestack()
go-proxy  |     /usr/local/go/src/runtime/asm_amd64.s:616 +0x7a fp=0xc00009bfd0 sp=0xc00009bfc8 pc=0x46f0fa
go-proxy  |
go-proxy  | goroutine 41 gp=0xc000412a80 m=4 mp=0xc000088008 [running]:
go-proxy  | main.(*UDPRoute).Handle(0xc0002ae4e0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x52 fp=0xc0205903a0 sp=0xc020590398 pc=0xb45af2
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc0205903c8 sp=0xc0205903a0 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc0205903f0 sp=0xc0205903c8 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590418 sp=0xc0205903f0 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590440 sp=0xc020590418 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590468 sp=0xc020590440 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590490 sp=0xc020590468 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc0205904b8 sp=0xc020590490 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc0205904e0 sp=0xc0205904b8 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590508 sp=0xc0205904e0 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590530 sp=0xc020590508 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590558 sp=0xc020590530 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590580 sp=0xc020590558 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc0205905a8 sp=0xc020590580 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc0205905d0 sp=0xc0205905a8 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc0205905f8 sp=0xc0205905d0 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590620 sp=0xc0205905f8 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590648 sp=0xc020590620 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590670 sp=0xc020590648 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590698 sp=0xc020590670 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc0205906c0 sp=0xc020590698 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc0205906e8 sp=0xc0205906c0 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590710 sp=0xc0205906e8 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590738 sp=0xc020590710 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590760 sp=0xc020590738 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590788 sp=0xc020590760 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc0205907b0 sp=0xc020590788 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc0205907d8 sp=0xc0205907b0 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590800 sp=0xc0205907d8 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590828 sp=0xc020590800 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590850 sp=0xc020590828 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590878 sp=0xc020590850 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc0205908a0 sp=0xc020590878 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc0205908c8 sp=0xc0205908a0 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc0205908f0 sp=0xc0205908c8 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590918 sp=0xc0205908f0 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590940 sp=0xc020590918 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590968 sp=0xc020590940 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590990 sp=0xc020590968 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc0205909b8 sp=0xc020590990 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc0205909e0 sp=0xc0205909b8 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590a08 sp=0xc0205909e0 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590a30 sp=0xc020590a08 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590a58 sp=0xc020590a30 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590a80 sp=0xc020590a58 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590aa8 sp=0xc020590a80 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590ad0 sp=0xc020590aa8 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590af8 sp=0xc020590ad0 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590b20 sp=0xc020590af8 pc=0xb45ad8
go-proxy  | main.(*UDPRoute).Handle(0x0?, {0xba02c0?, 0xc000314000?})
go-proxy  |     <autogenerated>:1 +0x38 fp=0xc020590b48 sp=0xc020590b20 pc=0xb45ad8
yusing commented 6 months ago

Should work now, also please update compose.yml to use image: ghcr.io/yusing/go-proxy instead of build: . 😄

earvingad commented 6 months ago

Yes, I can confirm udp forward is working now! Thanks for the support!