owntracks / docker-recorder

Docker image for OwnTracks Recorder
147 stars 68 forks source link

Example with mosquitto has Error: Connection refused #87

Open ChocolateLoverRaj opened 3 days ago

ChocolateLoverRaj commented 3 days ago

Docker version 27.3.1, build v27.3.1 My docker-compose.yml:

services:

  otrecorder:
    image: owntracks/recorder
    ports:
      - 8083:8083
    volumes:
      - config:/config
      - store:/store
    restart: unless-stopped
    environment:
      OTR_HOST: mosquitto

  mosquitto:
    image: eclipse-mosquitto
    ports:
      - 1883:1883
      - 8883:8883
    volumes:
      - mosquitto-data:/mosquitto/data
      - mosquitto-logs:/mosquitto/logs
      - mosquitto-conf:/mosquitto/config
    restart: unless-stopped

volumes:
  store:
  config:
  mosquitto-data:
  mosquitto-logs:
  mosquitto-conf:

Then I ran docker compose up as root and this happens:

[+] Running 2/2
 ✔ Container owntracks-mosquitto-1   Created                                                                                                                                                                                                           0.0s 
 ✔ Container owntracks-otrecorder-1  Recreated                                                                                                                                                                                                         0.3s 
Attaching to mosquitto-1, otrecorder-1
otrecorder-1  | + version 0.9.9 starting with STORAGEDIR=/store
otrecorder-1  | + connecting to MQTT on mosquitto:1883 as clientID ot-recorder-784ba286f037-6 without TLS
otrecorder-1  | Error: Connection refused
mosquitto-1   | 1730655922: mosquitto version 2.0.20 starting
mosquitto-1   | 1730655922: Config loaded from /mosquitto/config/mosquitto.conf.
mosquitto-1   | 1730655922: Starting in local only mode. Connections will only be possible from clients running on this machine.
mosquitto-1   | 1730655922: Create a configuration file which defines a listener to allow remote access.
mosquitto-1   | 1730655922: For more details see https://mosquitto.org/documentation/authentication-methods/
mosquitto-1   | 1730655922: Opening ipv4 listen socket on port 1883.
mosquitto-1   | 1730655922: Opening ipv6 listen socket on port 1883.
mosquitto-1   | 1730655922: mosquitto version 2.0.20 running
otrecorder-1 exited with code 0
otrecorder-1  | + version 0.9.9 starting with STORAGEDIR=/store
otrecorder-1  | + connecting to MQTT on mosquitto:1883 as clientID ot-recorder-784ba286f037-6 without TLS
otrecorder-1  | Error: Connection refused
otrecorder-1  | + version 0.9.9 starting with STORAGEDIR=/store
otrecorder-1  | + connecting to MQTT on mosquitto:1883 as clientID ot-recorder-784ba286f037-8 without TLS
otrecorder-1  | Error: Connection refused
otrecorder-1  | + version 0.9.9 starting with STORAGEDIR=/store
otrecorder-1  | + connecting to MQTT on mosquitto:1883 as clientID ot-recorder-784ba286f037-7 without TLS
otrecorder-1  | Error: Connection refused

and it keeps repeating the last 3 lines over and over.

Does the Docker with MQTT example need to be updated?

jpmens commented 2 days ago

can you show the content of config/mosquitto.conf ?

jpmens commented 2 days ago

Note in particular:

mosquitto-1   | 1730655922: Create a configuration file which defines a listener to allow remote access.
mosquitto-1   | 1730655922: For more details see https://mosquitto.org/documentation/authentication-methods/
jpmens commented 2 days ago

I think you are right in that the example doesn't work. This is what I've done to seemingly make it work:

$ mkdir config
$ cat | tee config/mosquitto.conf <<EOF
listener 1883
allow_anonymous true
EOF

Note the changed mounts in the docker compose file (docker-compose-mqtt.yml)

services:

  otrecorder:
    image: owntracks/recorder
    ports:
      - 8083:8083
    volumes:
      - config:/config
      - store:/store
    restart: unless-stopped
    environment:
      OTR_HOST: mosquitto

  mosquitto:
    image: eclipse-mosquitto
    ports:
      - 1883:1883
      - 8883:8883
    volumes:
      - ./config:/mosquitto/config/:rw
      - ./data:/mosquitto/data:rw
      - ./log:/mosquitto/log:rw
    restart: unless-stopped

volumes:
  store:
  config:
$ docker compose -f docker-compose-mqtt.yml up
Attaching to mosquitto-1, otrecorder-1
mosquitto-1   | 1730723136: mosquitto version 2.0.20 starting
mosquitto-1   | 1730723136: Config loaded from /mosquitto/config/mosquitto.conf.
mosquitto-1   | 1730723136: Opening ipv4 listen socket on port 1883.
mosquitto-1   | 1730723136: Opening ipv6 listen socket on port 1883.
mosquitto-1   | 1730723136: mosquitto version 2.0.20 running
otrecorder-1  | + version 0.9.9 starting with STORAGEDIR=/store
otrecorder-1  | + connecting to MQTT on mosquitto:1883 as clientID ot-recorder-8db6593673cb-8 without TLS
mosquitto-1   | 1730723136: New connection from 172.22.0.2:60896 on port 1883.
mosquitto-1   | 1730723136: New client connected from 172.22.0.2:60896 as ot-recorder-8db6593673cb-8 (p2, c0, k60).
otrecorder-1  | + HTTP listener started on 0.0.0.0:8083, without browser-apikey
otrecorder-1  | + HTTP prefix is unset
otrecorder-1  | + Using storage at /store with precision 7
otrecorder-1  | + Configured with revgeo=true and geokey: nil
otrecorder-1  | + TZDATADB is at /config/timezone16.bin: R_OK
otrecorder-1  | + Subscribing to owntracks/# (qos=2)

This definitely needs checking by somebody who knows what they're doing with docker.

ChocolateLoverRaj commented 2 days ago

With your changes it worked for me. Ideally the mosquitto configuration should be able to be configured in docker-compose.yml right?

jpmens commented 2 days ago

The path to the file can. Its content cannot, I think.