MQTT configuration from docker container to docker host

teddycloud is running just fine and now I want to connect the teddycloud server to my homeassistant instance.
teddycloud is running inside a docker container on the server where also HA is running and also my mosquitto server is running.
teddycloud has its own IP via compose file. When I configure the IP from the mosquitto server (192.168.0.111) the teddycloud logs displaying errors:

teddycloud | ERROR|mqtt.c:0340:mqttConnect| Failed to connect to MQTT: Access denied [271]
teddycloud | INFO |mqtt.c:0313:mqttConnect| Connect to ‘192.168.0.111’
teddycloud | INFO |mqtt.c:0333:mqttConnect| trying IP: 192.168.0.111

is there something I am missing in communitation between docker container to docker host?

My docker compose file:

version: '3'
services:
  teddycloud:
    container_name: teddycloud
    mac_address: 66-66-66-00-00-01
    hostname: teddycloud
    image: ghcr.io/toniebox-reverse-engineering/teddycloud:latest
    ports:
    - 80:80 #optional
    - 443:443 #Port is needed for the connection for the box
    dns:
    - 8.8.8.8
    - 192.168.0.1
    networks:
      web_net:
        ipv4_address: 192.168.0.222

    volumes:
      - certs:/teddycloud/certs
      - config:/teddycloud/config
      - content:/teddycloud/data/content
      - library:/teddycloud/data/library
      - firmware:/teddycloud/data/firmware
    restart: unless-stopped

volumes:
  certs:
  config:
  content:
  library:
  firmware:

networks:
  web_net:
    driver: bridge
#    driver_opts:
#      parent: enp2s0
#      com.docker.network.enable_ipv6: "false"
    ipam:
      driver: default
      config:
      - subnet: 192.168.0.0/24
        gateway: 192.168.0.1

Is your home assistant using MACvlan to get an IP? MACvlan only supports emulating one extra MAC address per physical port (ethernet port).

I was looking to do something similar, but found that HA does not like to play well with other devices trying to use it’s physical network adapter. I ended up using one of my spare raspberry PI’s to host HASS-OS, and run teddy cloud on my original host by itself.

I got it up and running.

I set docker to use the default bridge and assigned the additional 2nd IP to the host ethernet interface.
Now teddycloud can communicate to the MQTT Broker running on the host machine.

2 Likes

Hi,

I had the same issue. Thank you @ruN for your help.

In my case, I was using “macvlan” in the teddycloud Docker container and got the error “Failed to connect to MQTT: Access denied [271]” when trying to use MQTT. The MQTT broker (Mosquitto) was also running in a Docker container. Publishing MQTT messages from another host worked fine.

Following @ruN’s suggestion, I added a second IP address to my Docker host:

# /etc/network/interfaces
...
auto eth0:0
iface eth0:0 inet static
  address <your_secondary_ip>
  netmask 255.255.0.0

After that, I used this secondary IP address in my teddycloud Docker Compose file:

version: '3'
services:
  teddycloud:
    container_name: teddycloud
    hostname: teddycloud
    image: ghcr.io/toniebox-reverse-engineering/teddycloud:latest
    ports:
      - <your_secondary_ip>:80:80 # optional
      - <your_secondary_ip>:443:443 # needed for the box connection
    volumes:
      ...

EDIT

  • Added the filename /etc/network/interfaces

BR/zacharias