Skip to content

Commit 7285b32

Browse files
lpcoxCopilot
andcommitted
Make /etc/hosts write non-fatal for non-root container execution
gh-aw PR #26658 adds --user $(id -u):$(id -g) to the MCP gateway Docker run command so log files are readable by downstream steps. With set -e, the echo >> /etc/hosts in configure_host_dns() would abort the gateway when running as non-root. Fix: wrap the write in an if-else so failure is a warning, not fatal. With --network host the host.docker.internal mapping is unnecessary anyway since localhost works directly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 410d054 commit 7285b32

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

run_containerized.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,11 @@ configure_host_dns() {
285285
# Add host.docker.internal mapping to /etc/hosts
286286
# Check if the entry already exists to avoid duplicates
287287
if ! grep -q "host.docker.internal" /etc/hosts 2>/dev/null; then
288-
log_info "Adding host.docker.internal mapping to /etc/hosts"
289-
echo "$HOST_IP host.docker.internal" >> /etc/hosts
290-
log_info "DNS mapping configured: $HOST_IP -> host.docker.internal"
288+
if echo "$HOST_IP host.docker.internal" >> /etc/hosts 2>/dev/null; then
289+
log_info "DNS mapping configured: $HOST_IP -> host.docker.internal"
290+
else
291+
log_warn "Cannot write to /etc/hosts (running as non-root?); host.docker.internal mapping skipped"
292+
fi
291293
else
292294
log_info "host.docker.internal already exists in /etc/hosts"
293295
fi

0 commit comments

Comments
 (0)