Skip to content

Commit

Permalink
If MG_DOCKER_HOST it is used, resolve hostname if needed to avoid chi…
Browse files Browse the repository at this point in the history
…cken-and-egg problem
  • Loading branch information
imartinezortiz committed May 4, 2020
1 parent e58f758 commit 89d6309
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ FROM debian:10-slim
ADD build/dns-proxy-server-linux-amd64*.tgz /app/
WORKDIR /app
LABEL dps.container=true
VOLUME ["/var/run/docker.sock", "/var/run/docker.sock"]
CMD ["bash", "-c", "/app/dns-proxy-server"]
COPY overlay /
ENTRYPOINT ["/usr/bin/docker-entrypoint"]
CMD ["/app/dns-proxy-server"]
19 changes: 19 additions & 0 deletions overlay/usr/bin/docker-entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -eo pipefail
[[ "${MG_LOG_LEVEL}" == "DEBUG" ]] && set -x
set -u

if [[ "${MG_DOCKER_HOST:-x}" != "x" ]]; then
set +e
docker_host_name=$(echo "${MG_DOCKER_HOST}" | sed -r -e 's/^((tcp|tcps|http|https):\/\/)?([^\:]+)(:[[:digit:]]+)?$/\3/i')
docker_host_ip=$(echo "${docker_host_name}" | xargs getent hosts)
ret=$?
set -e
if [[ $ret -eq 0 ]]; then
# host ip found
docker_host_ip=$(echo "${docker_host_ip}" | cut -d ' ' -f 1)
export MG_DOCKER_HOST=$(echo "${MG_DOCKER_HOST}" | sed -r -e "s/^((tcp|tcps|http|https):\/\/)?([^\:]+)(:[[:digit:]]+)?$/\1${docker_host_ip}\4/i")
fi
fi

exec $@

0 comments on commit 89d6309

Please sign in to comment.