# Pihole is falling with failed to create listening socket

**URL:** <https://community.fly.io/t/pihole-is-falling-with-failed-to-create-listening-socket/4054>\
**Category:** Questions / Help\
**Created:** [February 12, 2022, 4:00pm UTC](https://community.fly.io/t/pihole-is-falling-with-failed-to-create-listening-socket/4054 "2022-02-12T16:00:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fly4](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/fly4/32/7668_2.png) [@fly4](https://community.fly.io/u/fly4)\
**Post date:** [February 12, 2022, 4:00pm UTC](https://community.fly.io/t/pihole-is-falling-with-failed-to-create-listening-socket/4054/1 "2022-02-12T16:00:34Z")

</div>

Hello,

I am trying to run pihole on free-tier but I am getting permission denied on port 53,

```auto
2022-02-12T15:26:22.000 [info] Using IPv4 and IPv6
2022-02-12T15:26:22.000 [info] ::: setup_blocklists now setting default blocklists up:
2022-02-12T15:26:22.000 [info] ::: TIP: Use a docker volume for /etc/pihole/adlists.list if you want to customize for first boot
2022-02-12T15:26:22.000 [info] ::: Blocklists (/etc/pihole/adlists.list) now set to:
2022-02-12T15:26:22.000 [info] https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
2022-02-12T15:26:22.000 [info] dnsmasq: failed to create li
2022-02-12T15:26:22.000 [info] dnsmasq: failed to create li↩︎tening socket for port 53: Permission denied
2022-02-12T15:26:22.000 [info] [cont-init.d] 20-start.sh: exited 1.
2022-02-12T15:26:22.000 [info] [cont-finish.d] executing container finish scripts...
2022-02-12T15:26:22.000 [info] [cont-finish.d] done.
2022-02-12T15:26:22.000 [info] [s6-finish] waiting for services.
2022-02-12T15:26:22.000 [info] Reaped child process with pid: 584, exit code: 0
2022-02-12T15:26:22.000 [info] Reaped child process with pid: 599, exit code: 0
2022-02-12T15:26:22.000 [info] Reaped child process with pid: 614, exit code: 0
2022-02-12T15:26:22.000 [info] Reaped child process with pid: 622, exit code: 0
2022-02-12T15:26:22.000 [info] Reaped child process with pid: 651, exit code: 0
2022-02-12T15:26:22.000 [info] Reaped child process with pid: 680, exit code: 0
2022-02-12T15:26:22.000 [info] Reaped child process with pid: 688, exit code: 0
2022-02-12T15:26:22.000 [info] Reaped child process with pid: 696, exit code: 0
2022-02-12T15:26:22.000 [info] Reaped child process with pid: 865, exit code: 0
2022-02-12T15:26:22.000 [info] [s6-finish] sending all processes the TERM signal.
2022-02-12T15:26:22.000 [info] hallpass exited, pid: 509, status: signal: 1
2022-02-12T15:26:22.000 [info] hallpass exited, pid: 870, status: signal: 15

```

Here is the fly.toml

```auto
app = "some-name"

kill_signal = "SIGINT"
kill_timeout = 5

[env]

[experimental]
  allowed_public_ports = []
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 80
  protocol = "tcp"
  script_checks = []

  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 6
    timeout = "2s"

[[services]]
  internal_port = 53
  protocol = "udp"

  [[services.ports]]
    port = "53"

```

Dockerfile

```auto
FROM pihole/pihole:latest
ENV INTERFACE eth0
ENV DNSMASQ_LISTENING ALL

```

Command to run it `flyctl launch` also I have tried with `flyctl deploy`

I am new to [fly.io](http://fly.io) 🙂

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![kurt](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/kurt/32/43757_2.png) [@kurt](https://community.fly.io/u/kurt)\
**Post date:** [February 12, 2022, 4:05pm UTC](https://community.fly.io/t/pihole-is-falling-with-failed-to-create-listening-socket/4054/2 "2022-02-12T16:05:11Z")

</div>

That’s weird, I wonder if something changed in the pihole image.

Try adding this to your Dockerfile:

```nohighlight
ENV DNSMASQ_USER=root

```

---

<div class="post-metadata">

**Author:** ![fly4](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/fly4/32/7668_2.png) [@fly4](https://community.fly.io/u/fly4)\
**Post date:** [February 12, 2022, 4:24pm UTC](https://community.fly.io/t/pihole-is-falling-with-failed-to-create-listening-socket/4054/3 "2022-02-12T16:24:26Z")

</div>

Hello @kurt,

You are awesome.

Thank you very much for your help!

It worked after mentioning user as root.

---

<div class="post-metadata">

**Author:** ![darkrain42](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@darkrain42](https://community.fly.io/u/darkrain42)\
**Post date:** [February 12, 2022, 9:59pm UTC](https://community.fly.io/t/pihole-is-falling-with-failed-to-create-listening-socket/4054/4 "2022-02-12T21:59:31Z")

</div>

docker-pihole 2022.1 defaults to running FTL (dnsmasq) as a non-root user, and [adds some capabilities to the pihole-FTL executable](https://github.com/pi-hole/docker-pi-hole/blob/6b5f746a15454bbeb242fc7e5afc8f68903bddf3/bash_functions.sh#L5-L13) (among other things, so pihole can create a listening socket on port 53!)

From what I can tell, the way they add those capabilities is compatible with running in Docker, but _not_ compatible with running in a lightweight VM (the way [fly.io](http://fly.io) does).

An alternative to kurt’s solution (“run as root”) is to change pihole-docker’s startup code to fix the permissions to work in fly. I have this in my Dockerfile, and it resolved the issue for me on fly. (I’m also dropping some other caps because I’m not using pihole for DHCP):

```auto
# Add 'permitted' cap to setcap command (setcap ...+ei to setcap ...+eip) and
# drop some of the permissions (CAP_NET_RAW, CAP_NET_ADMIN)
RUN set -ex \
    && sed -i -E -e 's/(setcap.*\+ei)([^p])/\1p\2/' \
                 -e 's/CAP_NET_(RAW|ADMIN),?//g' \
           /bash_functions.sh

```

---

<div class="post-metadata">

**Author:** ![darkrain42](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@darkrain42](https://community.fly.io/u/darkrain42)\
**Post date:** [April 2, 2022, 7:52pm UTC](https://community.fly.io/t/pihole-is-falling-with-failed-to-create-listening-socket/4054/5 "2022-04-02T19:52:42Z")

</div>

docker-pihole 2022.4.1 changes the way it handles capabilities even further, but is still not compatible with running on [fly.io](http://fly.io) without tweaks (either running pihole-FTL as root, or _different_ hacks to /bash\_functions.sh).

The pihole-FTL service will be in a restart loop:

```auto
2022-04-02T19:05:59Z [info]Starting pihole-FTL (no-daemon) as pihole
2022-04-02T19:05:59Z [info]Stopping pihole-FTL
2022-04-02T19:05:59Z [info]pihole-FTL: no process found

```

(/var/log/pihole-FTL will also show an error along the lines of “`failed to create listening socket for port 53 : Permission denied`”)

I’ve amended my previous Dockerfile modifications to the following:

```auto
# Override detection with hardcoded list of caps to provide to the pihole-FTL
# binary -- dropping some not needed (CAP_NET_RAW and CAP_NET_ADMIN). Fly.io
# doesn't run in docker, so the "detect based on current caps" logic won't
# work. The "capsh --print" added is just for debugging.
#
# https://github.com/pi-hole/docker-pi-hole/blob/70bad9f08f2651d686ae0e4ff374208265ad5ad9/bash_functions.sh#L10-L18
# (note the 'setcap' invocation trims the first character off the string,
# hence the leading ',')
RUN set -ex \
    && sed -i -E -e 's/^(\s+)(if \[\[\$\{CAP_STR\} \]\]; then)/\1capsh --print\n\1CAP_STR=",CAP_CHOWN,CAP_NET_BIND_SERVICE,CAP_SYS_NICE"\n\2/' \
           /bash_functions.sh

```
