Skip to content

Add host.docker.internal DNS resolution for containerized gateway#174

Merged
lpcox merged 2 commits intomainfrom
copilot/fix-dns-resolution-in-container
Jan 11, 2026
Merged

Add host.docker.internal DNS resolution for containerized gateway#174
lpcox merged 2 commits intomainfrom
copilot/fix-dns-resolution-in-container

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 11, 2026

The gateway container cannot resolve host.docker.internal on Linux, preventing connections to HTTP MCP servers running on the host.

Changes

  • run_containerized.sh: Added configure_host_dns() function that detects host IP and adds /etc/hosts entry
    • Tries multiple detection methods with fallbacks: primary interface → default gateway → docker0 bridge → 172.17.0.1
    • Called during startup after validation, before server launch
    • Checks for existing entries to avoid duplicates

Implementation

# Detect host IP and configure host.docker.internal DNS mapping
configure_host_dns() {
    log_info "Detecting host IP for container networking..."
    
    local HOST_IP=""
    
    # Method 1: Try to get the primary network interface IP (not loopback)
    HOST_IP=$(ip -4 addr show 2>/dev/null | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | grep -v '^127\.' | head -1)
    
    # Methods 2-4: Fallbacks...
    
    # Add host.docker.internal mapping to /etc/hosts
    if ! grep -q "host.docker.internal" /etc/hosts 2>/dev/null; then
        echo "$HOST_IP   host.docker.internal" >> /etc/hosts
        log_info "DNS mapping configured: $HOST_IP -> host.docker.internal"
    fi
}

The function integrates into the existing startup validation flow, executing after environment checks but before gateway initialization.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix DNS name resolution for host in container Add host.docker.internal DNS resolution for containerized gateway Jan 11, 2026
Copilot AI requested a review from lpcox January 11, 2026 21:43
@lpcox lpcox marked this pull request as ready for review January 11, 2026 21:44
@lpcox lpcox merged commit 2aeed8a into main Jan 11, 2026
@lpcox lpcox deleted the copilot/fix-dns-resolution-in-container branch January 11, 2026 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants