Changing web port when using Docker

How do I configure lighttpd.conf if I'm using docker? I didn't see any options to set it there.

In docker you don't need to change lighttpd port configuration. You just need to publish a different port for your container. This is how docker works.

Adding -p 8080:80 to your docker run command will publish the web interface on port 8080 (inside the container lighttpd will use the default port).

I'm using network_mode: "host"'', so I needed to get rid of the port mapping. I managed to configure and make it work using this configuration:

# More info at https://github.com/pi-hole/docker-pi-hole/ and https://docs.pi-hole.net/
version: '3'
services:
  pihole:
    restart: unless-stopped
    container_name: pihole
    image: pihole/pihole:nightly
    network_mode: "host"
    environment:
      TZ: 'America/Sao_Paulo'
      WEBPASSWORD: 'd57d1c269f44'
      DNSMASQ_LISTENING: 'all'
    # Volumes store your data between container upgrades
    volumes:
      - '/srv/data/pihole/etc-pihole:/etc/pihole'
      - '/srv/data/pihole/etc-dnsmasq.d:/etc/dnsmasq.d'
      - '/srv/wayhome-script/pihole/lighttpd:/etc/lighttpd'
    #   https://github.com/pi-hole/docker-pi-hole#note-on-capabilities
    cap_add:
      - NET_ADMIN # Required if you are using Pi-hole as your DHCP server, else not needed
      - CAP_SYS_NICE paste

The drawback of that is that I needed to first start pihole, let it populate the folder, then restart it.

If you'd want to switch away from port 80 when using Docker's host network mode, simply set the WEB_PORT environment variable for your Pi-hole container.

I tried that, it didn't work for metry it that, I did it didn't work for me. I think it doesn't work since the config is hard coded in lighttpd.conf

There is code in the docker start up script to replace the one inside the container's lighttpd.conf:

That said, I see you are volume mounting the /etc/lighttpd directory. Any reason for this? This may be causing all sorts of issues!

The reason was that I couldn't make the environment variable to work (I must have done something wrong that don't know now, since you are saying that it should work), so I mainly edited the config file and created it as a mount.

This will all be much easier with the v6 container as we wont need to deal with dynamically updating lighttpd config files

Not sure if you have a good solution here, however, I just ran into this using the v6 docker pihole version and the best workaround IMO was to just go ahead and update the pihole.toml file in the etc-pihole dir to use the ports you want to use under the [webserver] block:

  port = "8080o,8443os,[::]:8080o,[::]:8443os" ### CHANGED, default = "80o,443os,[::]:80o,[::]:443os"

Tested it by restarting the pihole container and now I can access the pihole dashboard at http://<ip address>:8080/admin/

Actually you can just put this as an env var for port 8443:443 and 8080:80 -

FTLCONF_webserver_port: '8080o,8443os,[::]:8080o,[::]:8443os'

FTLCONF_blockID_variable (this works for all vars in the pihole.toml conf file) and no need to edit the default conf file inside the container.

version: "3"

services:
pihole:
container_name: pihole
image: pihole/pihole:latest
ports:

  • "53:53/tcp"
  • "53:53/udp"
  • "8443:8443/tcp"
    environment:
    TZ: 'America/New_York'
    FTLCONF_webserver_api_password: 'xxxxx'
    FTLCONF_dns_listeningMode: 'all'
    FTLCONF_webserver_port: '8080o,8443os,[::]:8080o,[::]:8443os'
    WEB_PORT: 8443
    volumes:
  • './pihole/etc-pihole:/etc/pihole'
  • './pihole/etc-dnsmasq.d:/etc/dnsmasq.d'
    restart: unless-stopped
    network_mode: host

This is how I have mine setup.

PS this works for most docker projects out there with custom conf files. Just have to hunt around for the things like “FTLCONF” that maps these to the conf file. Cheers!

When you use network_mode: host the ports: section is ignored and can be removed from your compose file.

From Docker Docs - Host network driver:

Note

Given that the container does not have its own IP-address when using host mode networking, port-mapping doesn't take effect, and the -p, --publish, -P, and --publish-all option are ignored, producing a warning instead:

WARNING: Published ports are discarded when using host network mode