NativeConnection.connect is not finding temporal server on docker

Hello team,

I am running a docker image locally and getting the following error message:

docker run -p 80:80 -it [aws_id].dkr.ecr.us-west-2.amazonaws.com/temporal-workflows:12d8523b2e2ea02e911937e505c6a98dd5f6c22a
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
dummy log here
another 1
TransportError: tonic::transport::Error(Transport, hyper::Error(Connect, ConnectError("tcp connect error", Os { code: 99, kind: AddrNotAvailable, message: "Cannot assign requested address" })))
    at Function.connect (/opt/app-root/src/.yarn/cache/@temporalio-worker-npm-1.0.1-71d563dea6-c05226a9af.zip/node_modules/@temporalio/worker/lib/connection.js:56:23)
    at async run (/opt/app-root/src/packages/temporal-workflows/dist/main.js:30:18)

It seems to fail at this LoC where i try to connect to the temporal server:

  connection = await NativeConnection.connect({
    address: 'localhost:7233',
  });

but i have the temporal server running locally at that host:

➜  temporal-workflows git:(jackwang/solve-temporal-worker-bug) ✗ docker container ps
CONTAINER ID   IMAGE                                          COMMAND                  CREATED        STATUS              PORTS                                                                      NAMES
5f557fbcf05a   temporalio/ui:2.1.0                            "./start-ui-server.sh"   4 weeks ago    Up About a minute   0.0.0.0:8080->8080/tcp                                                     temporal-ui
61dbc0edc365   temporalio/admin-tools:1.17.0                  "tail -f /dev/null"      4 weeks ago    Up About a minute                                                                              temporal-admin-tools
34a21853fa49   temporalio/auto-setup:1.17.0                   "/etc/temporal/entry…"   4 weeks ago    Up About a minute   6933-6935/tcp, 6939/tcp, 7234-7235/tcp, 7239/tcp, 0.0.0.0:7233->7233/tcp   temporal
➜  temporal-workflows git:(jackwang/solve-temporal-worker-bug) ✗ docker port 34a21853fa49
7233/tcp -> 0.0.0.0:7233

What am i missing here?

Thanks!

Can you show result of
docker container ls --format "table {{.ID}}\t{{.Image}}\t{{.Names}}"

assuming the name of your container with id 34a21853fa49 is “temporal”
try:
address: 'temporal:7233',

CONTAINER ID   IMAGE                                          NAMES
5f557fbcf05a   temporalio/ui:2.1.0                            temporal-ui
61dbc0edc365   temporalio/admin-tools:1.17.0                  temporal-admin-tools
34a21853fa49   temporalio/auto-setup:1.17.0                   temporal

using temporal instead of localhost gives me the same error
EDIT: nvm i need to rebuild the image. lemme try that

Yea i rebuilt the image and ran it again and im getting the same error

Can you show your service def for your app in your docker compose?
Also I am not TS SDK expert but might be worth trying:

import { Connection, WorkflowClient } from '@temporalio/client';
...
const connection = await Connection.connect({
    address: 'temporal:7233'
});

That’s the Client snippet, which isn’t used for the Worker. I believe jwang is running the Worker?

Looks like the port is binding to 7233/tcp -> 0.0.0.0:7233. Can you get it to bind to localhost:7233 or 127.0.0.1:7233?

Sorry, how do i get it to bind on localhost?

What i have rn in my docker-compose is:

  temporal:
    container_name: temporal
    environment:
      - DB=sqlite
      - NUM_HISTORY_SHARDS=1
      - SKIP_SCHEMA_SETUP=true
      - DEFAULT_NAMESPACE=test
      - DYNAMIC_CONFIG_FILE_PATH=config/dynamicconfig/development-sql.yaml
    image: temporalio/auto-setup:${TEMPORAL_VERSION}
    networks:
      - temporal-network
    ports:
      - 7233:7233
    volumes:
      - ./docker/dynamicconfig:/etc/temporal/config/dynamicconfig
      - ${PWD}/docker/config_template.yaml:/etc/temporal/config/config_template.yaml

which follows from the example here: GitHub - temporalio/docker-compose: Temporal docker-compose files

When you create your container via docker run I believe in order for containers to communicate by name they should be on same network, so for example try adding

docker run ... --network <network>

using the previously mentioned docker container ls command you should be able to see the network name as well:

docker container ls --format "table {{.ID}}\t{{.Image}}\t{{.Names}}\t{{.Network}}"

see if that helps.

Alternatively just push your image to docker via docker push or docker build if you have a Dockerfile for it and then add your service via docker compose yaml something like:

  mydockerdemo:
    container_name: mydockerdemo
    depends_on:
      - temporal
    image: <your_docker_image>
    ports:
      - <port>:<port>

that didn’t work but this did:

temporal-workflows git:(jackwang/solve-temporal-worker-bug) docker run -p 80:80 --network host -it [aws_id].dkr.ecr.us-west-2.amazonaws.com/temporal-workflows:c0644904bf7f6df3ce46808af4c0d0e404e56ee7

thanks for pointing me in the right direction!