8000 introduced a new variable for containers, that should be ignored when… · Sengorius/docker-proxy-stack@19a9caf · GitHub
[go: up one dir, main page]

Skip to content

Commit 19a9caf

Browse files
author
Sengorius
committed
introduced a new variable for containers, that should be ignored when publishing the /etc/hosts file
1 parent 40f8ebf commit 19a9caf

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

.env.template

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ export WEB_CONTAINER_SUFFIXES="web"
2121
# separate multiple with pipes "|"
2222
export APP_CONTAINER_SUFFIXES="app|php"
2323

24+
# if you want to ignore some containers from getting their /etc/hosts file updated
25+
# with local adresses - e.g. DNS services or Pi-Hole - enter the container names
26+
# here and separate multiple with pipes "|"
27+
export IGNORED_HOSTS_CONTAINERS=""
28+
2429
# this will attach to the docker logs of the proxy containers after executing
2530
# `DockerExec proxy init` if set to 1
2631
export ATTACH_TO_COMPOSE_LOGS=1

DockerExec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export LINUX_HOSTS=/etc/hosts
1414
export STATUS_FILE_NAME="docker_current.txt"
1515
export TEMP_HOSTS_FILE=".current-hosts"
1616
export UPD_FILE_NAME=".last-update"
17+
export IGNORED_HOSTS_CONTAINERS="${IGNORED_HOSTS_CONTAINERS:-}"
1718

1819
export SRC_DIR="$BASE_DIR/src"
1920
export PROXY_ENV_FILE="$BASE_DIR/.env"
@@ -246,7 +247,7 @@ elif [[ "proxy" == "$ENVIRONMENT" ]]; then
246247
start_spawn_container "$file"
247248
done
248249

249-
# add all proxy containers (with there IP and hostname) to current hosts file
250+
# add all proxy containers (with their IP and hostname) to current hosts file
250251
update_host_files_with_proxy
251252
publish_host_files "APP"
252253

src/main.sh

8000
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ function update_host_files_with_proxy() {
283283
# update the /etc/hosts file in any proxy related container with data from .current-hosts file
284284
function publish_host_files() {
285285
local HOST_CONTAINER_SUFFIXES=($(echo "$1" | tr "|" "\n"))
286+
local IGNORED_CONTAINERS=($(echo "$IGNORED_HOSTS_CONTAINERS" | tr "|" "\n"))
286287
local FORMATTED_CONTAINERS=
287288

288289
for NEXT_SUFFIX in "${HOST_CONTAINER_SUFFIXES[@]}"; do
@@ -296,7 +297,7 @@ function publish_host_files() {
296297
PROXY_CONTAINERS=$(docker ps -a --format '{{ .Names }}' -f status='running' -f name='proxy-')
297298

298299
while read -r CURRENT; do
299-
if [[ -n "$CURRENT" ]]; then
300+
if [[ -n "$CURRENT" && ! "${IGNORED_CONTAINERS[*]}" =~ "$CURRENT" ]]; then
300301
CURRENT_CONTENT=$(docker exec -u root "$CURRENT" /bin/sh -c "cat /etc/hosts")
301302
CURRENT_CONTENT=$(echo "$CURRENT_CONTENT" | sed '/^### DockerExec hosts file update ###/,$d')
302303
UPDATED_HOSTS="$CURRENT_CONTENT\n### DockerExec hosts file update ###\n$(cat "$TEMP_HOSTS_PATH")"

0 commit comments

Comments
 (0)
0