From 26d841ccc7a04f8e5718c849186486f35f80c794 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 1 May 2024 13:54:30 -0700 Subject: [PATCH] aider: Add --add-host flag to docker run command to allow container to connect to host machine on macOS using host.docker.internal. # Aider chat conversation: USER: when i run `curl http://127.0.0.1:11434` inside the container, it "Couldn't connect to server". i want it to connect to the server running on the host computer on that port. the host is a mac. ASSISTANT: To allow the Docker container to connect to the host machine on macOS, you can use the special DNS name `host.docker.internal` which resolves to the internal IP address used by the host. This is a feature provided by Docker for Mac to facilitate such connections. Here's the diff to update the `docker.sh` script to include the `--add-host` flag, which adds an entry to the container's `/etc/hosts` file: ```diff --- benchmark/docker.sh +++ benchmark/docker.sh @@ ... @@ docker run \ -it --rm \ -v `pwd`:/aider \ -v `pwd`/tmp.benchmarks/.:/benchmarks \ -e OPENAI_API_KEY=$OPENAI_API_KEY \ -e HISTFILE=/aider/.bash_history \ -e AIDER_DOCKER=1 \ -e AIDER_BENCHMARK_DIR=/benchmarks \ + --add-host=host.docker.internal:host-gateway \ --net=host \ -p 11434:11434 \ aider-benchmark \ bash ``` With this change, when you run `curl http://host.docker.internal:11434` inside the container, it should connect to the server running on the host computer on that port. --- benchmark/docker.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/benchmark/docker.sh b/benchmark/docker.sh index 000ec7747..c045a48c6 100755 --- a/benchmark/docker.sh +++ b/benchmark/docker.sh @@ -8,6 +8,7 @@ docker run \ -e HISTFILE=/aider/.bash_history \ -e AIDER_DOCKER=1 \ -e AIDER_BENCHMARK_DIR=/benchmarks \ + --add-host=host.docker.internal:host-gateway \ --net=host \ -p 11434:11434 \ aider-benchmark \