ServerIP Environment variable doesn't appear to be a valid IPv4 address

Please follow the below template, it will help us to help you!

Expected Behaviour:

[PiHole starts dns server]

Actual Behaviour:

[Error message saying : [✗] DNS resolution is currently unavailable,]

I am running a docker container diginc/pi-hole on CoreELEC. I set up my container with the following command:

docker run -d \
    --name pihole \
    --network host \
    --cap-add NET_ADMIN \
    -v "/storage/.kodi/userdata/addon_data/docker.linuxserver.pihole/pihole/:/etc/pihole/" \
    -v "/storage/.kodi/userdata/addon_data/docker.linuxserver.pihole/dnsmasq.d/:/etc/dnsmasq.d/" \
    -e ServerIP="192.168.1.50" \
    -e WEBPASSWORD="xyz" \
    -e TZ="Asia/Karachi" \
    -e IPv6="False" \
    --restart=unless-stopped \
    diginc/pi-hole-multiarch:debian_armhf

The setup works fine until i reboot. After a reboot, if i check the log, it says:

DOCKER_REPO=multiarch/debian-debootstrap,
EUID=0,
FTL_CMD=no-daemon,,
),
HOME=/root,
HOSTNAME=CoreELEC,
HOSTTYPE=arm,
IFS=$' \t\n',
IPv6=False,
MACHTYPE=arm-unknown-linux-gnueabihf,
OPTERR=1,
OPTIND=1,
OSTYPE=linux-gnueabihf,
PATH=/opt/pihole:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin,
PHP_ENV_CONFIG=/etc/lighttpd/conf-enabled/15-fastcgi-php.conf,
PHP_ERROR_LOG=/var/log/lighttpd/error.log,
PIHOLE_INSTALL=/tmp/ph_install.sh,
PPID=212,
PS4='+ ',
PWD=/,
S6OVERLAY_RELEASE=https://github.com/just-containers/s6-overlay/releases/download/v1.21.2.2/s6-overlay-armhf.tar.gz,
S6_KEEP_ENV=1,
SHELL=/bin/bash,
SHELLOPTS=braceexpand:hashall:interactive-comments,
SHLVL=1,
ServerIP=192.168.1.50,
TAG=debian,,
b,
TZ=Asia/Karachi,
UBUNTU_SUITE=stretch,
UID=0,
WEBPASSWORD=xyz,
_=bash,
setupVars=/etc/pihole/setupVars.conf,
 ::: Starting docker specific setup for docker diginc/pi-hole,
RTNETLINK answers: Network is unreachable,
ERROR: ServerIP Environment variable (192.168.1.50) doesn't appear to be a valid IPv4 address,
  [✗] DNS resolution is currently unavailable,
  [i] Time until retry: 120
  [i] Time until retry: 120
  [i] Time until retry: 119
  [i] Time until retry: 118
.
.

After the 120s timeout, the server tries again, and according to the log its working, but the admin page says DNS server not active.

A simple restart of the container fixes all my problems and pihole starts functioning well. The problem happens after a host system reboot. What can i do to fix this ?

RTNETLINK answers: Network is unreachable,
A simple restart of the container fixes all my problems and pihole starts functioning well. The problem happens after a host system reboot. What can i do to fix this ?

I think because your docker container is started up before your system is completely online you need to add a delay before docker's service (or just my container) starts. This gives time for your networking to finish it's startup process and then the IP check shouldn't fail with that network unreachable error.

1 Like

That is exactly what i think it is, and i did some searching on adding a delay to the container startup but couldnt find anything. Could you guide me please

Setting docker's systemd service to have a dependency on whatever the networking stack service is called. LMGT link: systemd add dependency

The docker pi-hole readme has a systemd service to start the pi-hole container which could contain the same dependency on the network service too: GitHub - pi-hole/docker-pi-hole: Pi-hole in a docker container (I didn't write). This would replace the run commands' --restart arg

There's also some other docker-compose tricks Control startup order | Docker Docs however I'd try the above before resorting to this.

After a lot of googling, ive got timers to work, but the timer does not DELAY the startup of the services. The service still starts, even though the timer is counting down when i check with systemctl list-timers .

Is there any way to install pihole directly to my CoreELEC installation, without docker? i tried to, but bash gave me a syntax error :frowning:

Don't give up quite yet. Reviewing the situation it appears the latest docker systemd defaults to what I suggested, waiting for the network service.

Are you running the newest official version of docker from get.docker.com's installer? Also are you running wireless? I'm wondering if the network service is 'on' before the wireless kicks in.

Your idea for a timer may work, what was the timer command? In order to tell docker to stop auto starting the container and have your timer take over starting the container with a delay you'll need to delete the container with docker rm pihole then re-run it without --restart=unless-stopped which causes the on-boot startup.

I'm running the docker version from the CoreELEC repository:

Version: 17.10.0-ce
API version: 1.33
Go version: go1.9.2
Git commit: 17.10.0-ce
Built: Sat Jun 23 03:12:51 UTC 2018
OS/Arch: linux/arm

I'll try recreating the container without --restart=unless-stopped and report back in a bit.

I have one other problem. The docker container keeps adding

::1 localhost CoreELEC

to my hosts file along with 127.0.0.1. The ipv4 part is doing its job, but he ::1 (something related to ipv6) causes some dns resolution problems even though ive disabled ipv6. Any way to prevent pihole from adding stuff to my hosts file ?

I'm not super versed in IPv6 or --net host mode (this is what I think is modifying the host /etc/host, normally docker manages an isolated /etc/host inside the container instead) but there is lots of conversation on disabling ipv6. These two sound like they found something that worked: in systemd config and in container run port mapping

im running in net host mode, so i guess it IS modifying the system host file?

If you stop the docker service and it removes that from /etc/hosts then definitely true. I based that solely off what you said and the fact docker manages hosts inside non --net=host containers.

Are you sure you need --net=host and can't use the -p port forwards?

Maaan -p worked so much better overall, but i need the DHCP function as my ISP has blocked the option to change DNS on my router. I've tried most methods i could find, only the network host method worked.

Ok i have a non-starting pihole container, but i cant get it to start using the service:

[Unit]
Description=pihole
Requires=docker.service multi-user.target
After=docker.service network-online.target dhcpd.service

[Service]
Restart=always
ExecStart=/usr/bin/docker start -a pihole
ExecStop=/usr/bin/docker stop -t 2 pihole

[Install]
WantedBy=multi-user.target

The timer file has this:

[Unit]
Description=Runs pihole

[Timer]
OnBootSec=20s
Unit=pihole.service

[Install]
WantedBy=multi-user.target

Any tips?

Systemd logs / Journald should help trace the sequence of events.

Beyond that I'm not familiar enough with systemd to be much help at this level. I've never touched a timer in my life, maybe someone else sees an issue?

Thanks for your help. Leaving the timer out for now, i cant get the container to start using a service. If i can get that to work, the timer will work.

Just can't find the correct ExecStart command to start a container.

Does the /usr/bin/docker start -a pihole command work on a plain command line?

No it does not work, i get this:

-sh: /usr/bin/docker: not found

running docker start pihole works just fine though. I tried ExecStart=docker start pihole but it did not work

Maybe docker is installed to some other path? I'm not familiar with how ''app installation" works in linux really. Is there a way to check where docker is installed ? I'm guessing its something non-standard because it is CoreELEC/LibreELEC

Alright! SUCESS! Figured it out finally. Used docker info to get the complete path to docker and added it to my service file. Here's the code for anyone who might come here looking for help:
pihole.service

[Unit]
Description=pihole

[Service]
Restart=always
ExecStart=/storage/.kodi/addons/service.system.docker/bin/docker start -a pihole
ExecStop=/storage/.kodi/addons/service.system.docker/bin/docker stop -t 2 pihole

[Install]
WantedBy=multi-user.target

pihole.timer

[Unit]
Description=Runs pihole

[Timer]
OnBootSec=60s
Unit=pihole.service

[Install]
WantedBy=multi-user.target
Blockquote

This will basically start the container using the service, and the timer will let you modify how long after boot the service starts. Thanks man! Really impressed with the one-on-one support here!

1 Like

:+1: Glad we got it sorted. CoreELEC sounds interesting, I may have to test it sometime.

About the ipv6 problem: I have an app on my android phone that can browse the smb on my CoreELEC system at ip 192.168.1.50. The ::1 in the hosts file messes with this somehow:

dnsmasq: 37 127.0.0.1/59470 query[A] pi.hole from 127.0.0.1
dnsmasq: 37 127.0.0.1/59470 /etc/pihole/local.list pi.hole is 192.168.1.50
dnsmasq: 38 192.168.1.247/2682 query[AAAA] COREELEC from 192.168.1.247
> dnsmasq: 38 192.168.1.247/2682 /etc/hosts COREELEC is ::1
dnsmasq: 39 192.168.1.247/19618 query[A] COREELEC from 192.168.1.247
dnsmasq: 39 192.168.1.247/19618 /etc/pihole/local.list COREELEC is 192.168.1.50

If i manually remove that line from the hosts file, this scenario plays out fine. But after a restart of the container, that line comes back and im back to square one.