growthbook / growthbook-proxy

:zap: GrowthBook Proxy Server - Caching, Streaming, Security, and Scalability
MIT License
25 stars 13 forks source link

Error with docker : ECONNREFUSED #39

Closed lud-wj closed 1 year ago

lud-wj commented 1 year ago

I'm trying to follow the docs with this configuration:

  mongo:
    image: "mongo:latest"
    environment:
      - MONGO_INITDB_ROOT_USERNAME=root
      - MONGO_INITDB_ROOT_PASSWORD=password
    volumes:
      - mongodata:/data/db

  growthbook:
    image: "growthbook/growthbook:latest"
    ports:
      - "3000:3000"
      - "3100:3100"
    depends_on:
      - mongo
    environment:
      - MONGODB_URI=mongodb://root:password@mongo:27017/growthbook?authSource=admin
      # Proxy settings
      - PROXY_ENABLED=1
      - PROXY_HOST_INTERNAL=http://proxy:3300
      - PROXY_HOST_PUBLIC=http://localhost:3300
      # Change this to something secure in production!
      - SECRET_API_KEY=dev
    volumes:
      - uploads:/usr/local/src/app/packages/back-end/uploads

  proxy:
    image: "growthbook/proxy:latest"
    ports:
      - "3300:3300"
    depends_on:
      - growthbook
    environment:
      - GROWTHBOOK_API_HOST=http://growthbook:3100
      # This must match the SECRET_API_KEY above
      - SECRET_API_KEY=dev

volumes:
  uploads:
  mongodata:

But the proxy will just exit :

src-proxy-1       | yarn run v1.22.19
src-growthbook-1  | ready - started server on 0.0.0.0:3000, url: http://localhost:3000
src-proxy-1       | $ wsrun -p @growthbook/proxy -c start
src-proxy-1       | @growthbook/proxy
src-proxy-1       |  | $ node dist/index.js
src-proxy-1       |  | (node:48) [DEP0111] DeprecationWarning: Access to process.binding('http_parser') is deprecated.
src-proxy-1       |  | (Use `node --trace-deprecation ...` to show where the warning was created)
src-proxy-1       |  | GrowthBook proxy running over HTTP1.1, port 3300
src-proxy-1       |  | node:internal/deps/undici/undici:11372
src-proxy-1       |  |     Error.captureStackTrace(err, this);
src-proxy-1       |  |           ^
src-proxy-1       |  | 
src-proxy-1       |  | TypeError: fetch failed
src-proxy-1       |  |     at Object.fetch (node:internal/deps/undici/undici:11372:11)
src-proxy-1       |  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
src-proxy-1       |  |   cause: Error: connect ECONNREFUSED 172.21.0.3:3100
src-proxy-1       |  |       at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {
src-proxy-1       |  |     errno: -111,
src-proxy-1       |  |     code: 'ECONNREFUSED',
src-proxy-1       |  |     syscall: 'connect',
src-proxy-1       |  |     address: '172.21.0.3',
src-proxy-1       |  |     port: 3100
src-proxy-1       |  |   }
src-proxy-1       |  | }
src-proxy-1       |  | 
src-proxy-1       |  | Node.js v18.18.2
src-proxy-1       |  | error Command failed with exit code 1.
src-proxy-1       |  | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
src-proxy-1       |  | `yarn start` failed with exit code 1
src-proxy-1       | error Command failed with exit code 1.
src-proxy-1       | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

The ports seem to work well:

curl http://localhost:3100/
{
  "name": "GrowthBook API",
  "production": false,
  "api_host": "http://localhost:3100",
  "app_origin": "http://localhost:3000",
  "config_source": "db",
  "email_enabled": false,
  "build": {
    "sha": "f9349da702a37711118e1daf429f4475c6ea22ca",
    "date": "2023-10-30T22:43:19Z"
  }
}                                                                                                        

curl http://172.21.0.3:3100/
{
  "name": "GrowthBook API",
  "production": false,
  "api_host": "http://172.21.0.3:3100",
  "app_origin": "http://localhost:3000",
  "config_source": "db",
  "email_enabled": false,
  "build": {
    "sha": "f9349da702a37711118e1daf429f4475c6ea22ca",
    "date": "2023-10-30T22:43:19Z"
  }
}

So maybe a bug?

lud-wj commented 1 year ago

OK I added this to growthbook service:

    healthcheck:
      test: ["CMD", "wget", "http://localhost:3100"]
      interval: 1s
      timeout: 1s
      retries: 10

And changed the proxy service with this:

    depends_on:
      growthbook:
        condition: service_healthy