Skip to content

Commit

Permalink
feat: allow customizing listening port via environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
pascaliske committed Dec 18, 2022
1 parent e6f8424 commit 14f815e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
14 changes: 9 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@ RUN case ${TARGETPLATFORM} in \
FROM alpine:3.17
LABEL maintainer="[email protected]"

# environment
ENV UNBOUND_PORT=5053

# install unbound
RUN apk update && apk upgrade && apk add --no-cache \
gettext \
bind-tools \
openssl \
unbound

# inject built files
COPY --from=tini /tini /sbin/tini

# inkect config files
COPY config/unbound.conf /etc/unbound/unbound.conf
# inject config files
COPY config/unbound.conf.tpl /etc/unbound/unbound.conf.tpl

# inject entrypoint
COPY docker-entrypoint.sh /docker-entrypoint.sh
Expand All @@ -38,11 +42,11 @@ COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN echo "net.core.rmem_max=1048576" >> /etc/sysctl.conf

# health check
HEALTHCHECK CMD dig @127.0.0.1 -p 5053 cloudflare.com || exit 1
HEALTHCHECK CMD dig @127.0.0.1 -p ${UNBOUND_PORT} cloudflare.com || exit 1

# expose port
EXPOSE 5053/tcp
EXPOSE 5053/udp
EXPOSE ${UNBOUND_PORT}/tcp
EXPOSE ${UNBOUND_PORT}/udp

# let's go!
ENTRYPOINT [ "/sbin/tini", "--", "/docker-entrypoint.sh" ]
Expand Down
2 changes: 1 addition & 1 deletion config/unbound.conf → config/unbound.conf.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ server:

# network
interface: 0.0.0.0
port: 5053
port: ${UNBOUND_PORT}

# response
do-ip4: yes
Expand Down
4 changes: 4 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/sh
# -*- coding: utf-8 -*-

# dynamically set port from environment variable
# shellcheck disable=SC2016
envsubst '$UNBOUND_PORT' < /etc/unbound/unbound.conf.tpl > /etc/unbound/unbound.conf

# exec container command
exec "$@"

0 comments on commit 14f815e

Please sign in to comment.