Trying to combine projects on one Pi

Complete beginner here, trying to follow the instructions in this article to combine the Balena Home Assistant and Balena PiHole projects on a RPi 4B, 4GB variant. I’ve worked through several releases and finally have all containers running but usually wind up either not being able to access the PiHole interface or the Home Assistant interface. In my current build, when I browse to the internal IP of my Pi, I get the PiHole admin interface. using when I try the IP as x.x.x.x:8213, I get a connection refused error. I can get to the configurator interface at x.x.x.x:3128 and I can reach the MQTT broker at x.x…x.x:1883.

I’m not sure where I’ve gone wrong here, and I’m not sure what the best way is to ask for help. Should I post the text of my docker-compose file?

1 Like

Posting the docker compose file can never hurt - there’s likely a networking issue going on here and seeing the docker compose might help identify it quickly :slight_smile:

OK, the forum won’t let me upload it, going to try to copy/paste it and see how this goes. The port 4199 is where I’m trying to enable the HomeAssistant container to listen on port 4199 for this integration

version: '2'
volumes:
    config:
    mosquitto:
    pihole_config:
    dnsmasq_config:
services:
  pihole: 
    build: pihole
    ports: 
      - 8080:80 
    cap_add:
      - SYS_TTY_CONFIG
      - NET_ADMIN
    volumes:
      - "pihole_config:/etc/pihole"
      - "dnsmasq_config:/etc/dnsmasq.d"
    dns:
      - "127.0.0.1"
      - "1.1.1.1"
    network_mode: host
    labels:
      io.balena.features.dbus: "1"
    devices:
      - /dev/tty0
      - /dev/tty1

  unbound:
    build: unbound
    ports:
      - "5053:5053/tcp"
      - "5053:5053/udp"

  # https://github.com/balenablocks/fbcp
  fbcp:
    image: balenablocks/fbcp:1.0.0
    privileged: true

  # https://github.com/balenablocks/hostname
  hostname:
    build: hostname
    restart: no
    labels:
      io.balena.features.supervisor-api: 1
    environment:
      SET_HOSTNAME: HomeHole
  homeassistant:
    build: homeassistant
    ports:
      - 8123:80
      - 4199:4199
    privileged: true
    volumes:
      - 'config:/config'
    restart: always
  mqtt:
    build: mqtt
    ports:
      - "1883:1883"
    restart: always
    volumes:
      - mosquitto:/mosquitto/data
  hass-configurator:
    image: "causticlab/hass-configurator-docker:latest"
    restart: always
    ports:
      - "3218:3218"
    volumes:
      - 'config:/hass-config'
    environment:
      - HC_BASEPATH=/hass-config

Hey, nice one I can see the docker compose just fine.

homeassistant:
    build: homeassistant
    ports:
      - 8123:80

This is mapping the HOST port 8123 to port 80 of the homeassistant container - can you confirm that there is something listening on port 80 of that container?

image
Seems like there isn’t. Should that be 8123:8123 instead? I may have messed up something when combining the two docker-compose files.

Here’s the section for home assistant from the original Balena-Home Assistant project:

services:
  homeassistant:
    build: homeassistant
    ports:
      - 80:8123
    privileged: true
    volumes:
      - 'config:/config'
    restart: always

hey there, you’re right - if that was in the original docker compose then its likley home assistant is listening on port 8123 of the container - so 8123:8123 should lead to it being exposed on :8123 like your other services

In the original home assistant project, port 80 of the host was being forwarded to port 8123 of the container - probably as that would make it available on just <host IP> or the balena cloud public url :slight_smile:

1 Like

That did it! set it to 8123:8123 and pushed a new release and now x.x.x.x goes straight to the PiHole and x.x.x.x:8123 takes me to HomeAssistant.

Thanks for all the help!

Edit:

OK, ran into a problem. While everything is working, I can’t access Home Assistant via the public URL and I think it’s because that only allows access to Port 80. I thought that I could just swap ports and point the PiHole instance to another port since I can manage it from within Home Assistant but now that I’ve done it, I can’t get HA to launch - the container just shows “installed” and it keeps trying to launch over and over. I guess that’s why the port was set up to be forwarded in the base version, so that it could be accessed from the URL.

version: '2'
volumes:
    config:
    mosquitto:
    pihole_config:
    dnsmasq_config:
services:
  pihole: 
    build: pihole
    ports: 
      - 8080:8080 
    cap_add:
      - SYS_TTY_CONFIG
      - NET_ADMIN
    volumes:
      - "pihole_config:/etc/pihole"
      - "dnsmasq_config:/etc/dnsmasq.d"
    dns:
      - "127.0.0.1"
      - "1.1.1.1"
    network_mode: host
    labels:
      io.balena.features.dbus: "1"
    devices:
      - /dev/tty0
      - /dev/tty1

  unbound:
    build: unbound
    ports:
      - "5053:5053/tcp"
      - "5053:5053/udp"

  # https://github.com/balenablocks/fbcp
  fbcp:
    image: balenablocks/fbcp:1.0.0
    privileged: true

  # https://github.com/balenablocks/hostname
  hostname:
    build: hostname
    restart: no
    labels:
      io.balena.features.supervisor-api: 1
    environment:
      SET_HOSTNAME: HomeHole
  homeassistant:
    build: homeassistant
    ports:
      - 80:8123
      - 4199:4199
    privileged: true
    volumes:
      - 'config:/config'
    restart: always
  mqtt:
    build: mqtt
    ports:
      - "1883:1883"
    restart: always
    volumes:
      - mosquitto:/mosquitto/data
  hass-configurator:
    image: "causticlab/hass-configurator-docker:latest"
    restart: always
    ports:
      - "3218:3218"
    volumes:
      - 'config:/hass-config'
    environment:
      - HC_BASEPATH=/hass-config

Hi there, you’re right - the public url gives access to port 80, so if you want to access home assistant to it, you’ll have to map the host port 80, to the port being listened to by home-assistant, as you have done in your docker-compose.

Do you see any log messages in the terminal in the dashboard that indicate what the error might be?

Is it possible that pihole is listening on port 80? It is in host mode networking, which means that if whatever is inside the pihole container listens on port 80 - then it is using host port 80. As you are forwarding host port 80 now to port 8123 for home assistant, I wonder if that leads to some sort of port conflict that’s causing the home assistant container to error and restart

I think this might be it - looking at the docker image the pihole hub app is based on GitHub - pi-hole/docker-pi-hole: Pi-hole in a docker container , pihole uses port 80 for its web interface by default - as its in host networking mode (I think this is required too), this means it will hog port 80 on your device. This will lead to a port conflict when mapping port 80 to anything else (homeassistant container in your case).

What to do about it - I’m not entirely sure

  • maybe there’s a way to change pihole so it isn’t using port 80
  • I think its the web interface that is using port 80 - maybe there’s a way to disable it to free up port 80?
  • can pihole be used outside of network_mode: host? Docker Hub suggests it can be - but you won’t be able to use its DHCP

I’m not that familiar with pihole so can’t say for sure!

Hey,

I know it’s not much help, but I ran into the same issue a week ago and managed to force pihole to run it’s admin interface on a different port. The solution included an sed command that I put into the dockerfile of the PiHole, and the sed command I found somewhere online basically changed the port number in the config files when building the image.

I can look for the dockerfile and the place where I found this solution if needed.

Hi,

I can think of a couple of solutions.
One is to run a proxy (pihole example, generic example), that redirects certain subdomains to certain containers.
You could have nginx config entries like

server {
    listen 80;
    server_name ha.*;

    proxy_pass http://homeassistant:8123$request_uri;
}


server {
    listen 80;
    server_name *;

    proxy_pass http://pihole$request_uri;
}

That would make nginx listen on port 80 and forward ha.<public URL> to homeassistant and <public URL> to pihole.

Other (if you’re keen on using network=host) is to try your luck with the pi hole docker environment variable WEB_PORT as described in the readme
In the sources it looks like this changes the management port from 80 to whatever you filled in.

I have zero experience with pihole and homeassistant though, this is just from my experience with nginx reverse proxies in docker-compose :slight_smile:

1 Like

Great idea @TJvV i will try it myself!

@MadScientist67 BTW welcome to the balena community! I think balenaCloud Public URL also accepts the port 8080, if i’m not wrong.

Now you have 2 possible solutions, let us know if that works for you :slight_smile:

Thanks everyone, this wound up taking a backseat for a few days, but I’m hoping to get back to it this weekend. I’ll give this a shot and let y’all know

1 Like

OK, got some time to play with things this morning.

Taking a little bit from everyone, I used the WEB_PORT variable and set to 8080 and changed the port in the docker-compose file to 8080 as well and everything seems to be working OK.

Here’s the docker-compose in case this will help someone else in the future that stumbles across this thread.

version: '2'
volumes:
    config:
    mosquitto:
    pihole_config:
    dnsmasq_config:
services:
  pihole: 
    build: pihole
    ports: 
    - "80:8080"
    cap_add:
      - SYS_TTY_CONFIG
      - NET_ADMIN
    volumes:
      - "pihole_config:/etc/pihole"
      - "dnsmasq_config:/etc/dnsmasq.d"
    dns:
      - "127.0.0.1"
      - "1.1.1.1"
    network_mode: host
    labels:
      io.balena.features.dbus: "1"
    devices:
      - /dev/tty0
      - /dev/tty1

  unbound:
    build: unbound
    ports:
      - "5053:5053/tcp"
      - "5053:5053/udp"

  # https://github.com/balenablocks/hostname
  hostname:
    build: hostname
    restart: no
    labels:
      io.balena.features.supervisor-api: 1
    environment:
      SET_HOSTNAME: HomeHole
  homeassistant:
    build: homeassistant
    ports:
      - 80:8123
    privileged: true
    volumes:
      - 'config:/config'
    restart: always
  mqtt:
    build: mqtt
    ports:
      - "1883:1883"
    restart: always
    volumes:
      - mosquitto:/mosquitto/data
  hass-configurator:
    image: "causticlab/hass-configurator-docker:latest"
    restart: always
    ports:
      - "3218:3218"
    volumes:
      - 'config:/hass-config'
    environment:
      - HC_BASEPATH=/hass-config

2 Likes

Thank you @MadScientist67 for sharing your solution!