defrecord / anthropic-quickstarts

A collection of projects designed to help developers quickly get started with building deployable applications using the Anthropic API
MIT License
2 stars 0 forks source link

Fix: Resolve Port Mapping Through Enclave to Host #3

Open aygp-dr opened 3 days ago

aygp-dr commented 3 days ago

Port Mapping Issue in Nested Docker (DinD) Environment

Issue

Cannot access ComputerUse demo from host when running in Docker-in-Docker environment

Current Behavior

Host machine cannot access ComputerUse demo's web interfaces through mapped ports (8080, 8501, 5900, 6080) when running in nested Docker configuration.

Expected Behavior

All ComputerUse demo ports should be accessible from host machine:

Investigation Results

✅ Working Configuration

# In Enclave (DinD)
docker run -it --privileged \
    -v $HOME/.anthropic:/root/.anthropic \
    -p 8080:8080 -p 8501:8501 -p 5900:5900 -p 6080:6080 \
    docker:dind sh -c 'dockerd > /var/log/dockerd.log 2>&1 & sleep 3 && /bin/sh'

# Then inside Enclave:
docker run -it \
    -v /root/.anthropic:/home/computeruse/.anthropic \
    --network host \
    ghcr.io/anthropics/anthropic-quickstarts:computer-use-demo-latest

❌ Non-working Configuration

docker run -it --net=host --privileged -it \
    -v $HOME/.anthropic:/root/.anthropic \
    -p 8080:8080 -p 8501:8501 -p 5900:5900 -p 6080:6080 \
    docker:dind \
    docker run -it \
        -v /root/.anthropic:/home/computeruse/.anthropic \
        -p 8080:8080 -p 8501:8501 -p 5900:5900 -p 6080:6080 \
        ghcr.io/anthropics/anthropic-quickstarts:computer-use-demo-latest

Solution

  1. Split the container startup into two steps
  2. Use --network host in the ComputerUse container
  3. Start Docker daemon before running nested container
  4. Remove duplicate port mappings

Implementation

The solution has been documented in infrastructure.org with:

Related

Labels

jwalsh commented 3 days ago

Initial testing work on DinD is noted in https://github.com/defrecord/anthropic-quickstarts/blob/main/computer-use-demo/infrastructure.org

jwalsh commented 3 days ago

Context examples:

1. Host (Darwin)
  - Hostname: [REDACTED]
  - User: [REDACTED]
  - Load: 1.89 1.86 1.89
  - Users: 7

2. Enclave (Alpine)
  - Hostname: 764c38cc43d3
  - User: root
  - Load: 0.04, 0.09, 0.04
  - Users: 0

3. ComputerUse (Ubuntu)
  - Hostname: 764c38cc43d3 (same as Enclave)
  - User: computeruse
  - Load: 0.03, 0.09, 0.04
  - Users: 0