From 7cb58b00b54127e9bcd9544c7226b18219476d73 Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Mon, 28 Aug 2023 20:45:59 +0200 Subject: [PATCH] Use consul DNS inside the container to resolve service.consul. --- nomad/Dockerfile | 7 +++++-- nomad/consul_config.hcl | 1 + nomad/entrypoint.sh | 10 ++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100755 nomad/entrypoint.sh diff --git a/nomad/Dockerfile b/nomad/Dockerfile index 5fbb395..0eb45f0 100644 --- a/nomad/Dockerfile +++ b/nomad/Dockerfile @@ -124,5 +124,8 @@ COPY supervisord.conf /etc/supervisor/supervisord.conf VOLUME /var/lib/docker ENV JAVA_HOME=/usr/lib/jvm/openjdk PATH="/usr/lib/jvm/openjdk/bin:$PATH" -ENTRYPOINT ["/usr/bin/supervisord"] -CMD ["-c", "/etc/supervisor/supervisord.conf"] + +COPY --chmod=0755 entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] +CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"] diff --git a/nomad/consul_config.hcl b/nomad/consul_config.hcl index 093ef77..62a69e7 100644 --- a/nomad/consul_config.hcl +++ b/nomad/consul_config.hcl @@ -9,6 +9,7 @@ advertise_addr = "{{GetInterfaceIP \"eth0\"}}" ports { grpc = 8502 + dns = 53 } connect { diff --git a/nomad/entrypoint.sh b/nomad/entrypoint.sh new file mode 100755 index 0000000..86df04d --- /dev/null +++ b/nomad/entrypoint.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# Keep DNS intact if we are not running supervisord & as such consul +if [[ "x$1" == "x/usr/bin/supervisord" ]]; then + ip addr add dev eth0 169.254.1.1 + echo -n "recursors = " > /etc/consul.d/config/00_recursors.hcl + echo $(grep -E '^nameserver ' /etc/resolv.conf|cut -f 2 -d " "|jq -cnR '[inputs | select(length>0)]') >> /etc/consul.d/config/00_recursors.hcl + echo "$(grep -vE '^nameserver ' /etc/resolv.conf)" > /etc/resolv.conf + echo "nameserver 169.254.1.1" >> /etc/resolv.conf +fi +exec "$@"