Skip to content

Commit 68ce183

Browse files
authored
Make /etc/hosts write non-fatal for non-root container execution (#3985)
## Context Companion to [gh-aw#26658](github/gh-aw#26658), which adds `--user $(id -u):$(id -g)` to the MCP gateway Docker run command so log files written via `/tmp` bind mounts are readable by downstream redaction and upload steps. ## Problem `run_containerized.sh` runs with `set -e` and unconditionally writes to `/etc/hosts` (line 289): ```bash echo "$HOST_IP host.docker.internal" >> /etc/hosts ``` When the container runs as a non-root user, this write fails with EACCES, aborting the entire gateway startup. ## Fix Wrap the `/etc/hosts` write in an if-else so failure produces a warning instead of aborting. With `--network host` (which the gateway always uses), the `host.docker.internal` mapping is unnecessary since `localhost` works directly. ## Changes | File | Change | |------|--------| | `run_containerized.sh` | Make `/etc/hosts` write non-fatal; log warning on failure | `make agent-finished` ✓
2 parents 410d054 + 9459dd3 commit 68ce183

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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)