sytone / obsidian-remote

Run Obsidian.md in a browser via a docker container.
MIT License
1.39k stars 134 forks source link

Exposing Port for API not working #46

Open JamborJan opened 1 year ago

JamborJan commented 1 year ago

Describe the bug I exposed the port for the obsidian-local-rest-api extension in two ways:

In both cases I cannot access the API.

To Reproduce Steps to reproduce the behavior:

  1. Startup container as described in the example yaml
  2. Install the obsidian-local-rest-api extension, enable http only API access
  3. Add the port for the API
  4. Run curl in the container of obsidian remote: curl localhost:27123, you'll get the status info of the API
  5. Run curl from another client with the proper working traefik service: you'll get something like this: curl: (7) Failed to connect to 172.29.52.3 port 27123: Connection refused
  6. You can setup also a port mapping from the container to the docker host. curl will not work as well, the error will be something like this: curl: (7) Failed to connect to 192.168.0.1 port 27123 after 111 ms: Couldn't connect to server

Expected behavior I would expect that exposing the API port 27123 would work exactly like port 8080 works. In the described setup exposing 8080 works. The same doesn't work for 27123. Thats the used docker-compose.yml:

services:

  obsidian:
    # source: https://github.com/sytone/obsidian-remote/pkgs/container/obsidian-remote
    container_name: obsidian
    hostname: obsidian
    image: ghcr.io/sytone/obsidian-remote:0.1.1
    restart: unless-stopped
    user: ${UID}:${GID} #PUID=1000:PGID=100
    expose:
      - 8080 # UI
      - 27123 # REST API insecure
      - 27124 # REST API TLS
    environment:
      - PUID=${UID}
      - PGID=${GID}
      - TZ=Europe/Zurich
      - KEYBOARD=de-ch-qwertz
    volumes:
      - '${CT_DATA_BASEPATH}/container/obsidian/vaults:/vaults'
      - '${CT_DATA_BASEPATH}/container/obsidian/config:/config'
    labels:
      - "traefik.enable=true"
      # UI
      - "traefik.http.routers.obsidian.rule=Host(`obsidian.${INSTANCE}.domain.tld`)"
      - "traefik.http.routers.obsidian.entrypoints=websecure"
      - "traefik.http.routers.obsidian.tls.certresolver=mytlschallenge"
      - "traefik.http.routers.obsidian.service=obsidian"
      - "traefik.http.services.obsidian.loadbalancer.server.port=8080"
      # API
      - "traefik.http.routers.obsidianapi.rule=Host(`obsidianapi.${INSTANCE}.domain.tld`)"
      - "traefik.http.routers.obsidianapi.entrypoints=websecure"
      - "traefik.http.routers.obsidianapi.tls.certresolver=mytlschallenge"
      - "traefik.http.routers.obsidianapi.service=obsidianapi"
      - "traefik.http.services.obsidianapi.loadbalancer.server.port=27123"
      # IP Whitelist
      - "traefik.http.routers.obsidian.middlewares=TestIP@docker"
      - "traefik.http.routers.obsidianapi.middlewares=TestIP@docker"
      # Basic auth user
      #- "traefik.http.routers.obsidian.middlewares=TestAuth@docker"
      # Flame app dashboard
      - "flame.type=application" # "app" works too
      - "flame.name=obsidian"
      - "flame.url=https://obsidian.${INSTANCE}.domain.tld"
      - "flame.icon=note-multiple-outline" # optional, default is "docker", source: https://materialdesignicons.com/
    logging:
      driver: "json-file"
      options:
        tag: "{{.ImageName}}|{{.Name}}|{{.ImageFullID}}|{{.FullID}}"
    networks:
      - TestDockerLAN

networks:
  TestDockerLAN:
    external:
      name: TestDockerLAN
JamborJan commented 1 year ago

It seems the behavior is deliberately and is discussed here:

https://github.com/coddingtonbear/obsidian-local-rest-api/discussions/18

How has anybody ever got the API working in docker?