Worker can't connect to Temporal

Hi there !
I’m new to Temporal and love the project but I got an issue while running the hello world tutorial from the doc (https://docs.temporal.io/docs/go-hello-world)
I’m trying to go a little further and run the worker in a docker container but it crash with the following error

unable to create Temporal client health check error: last connection error: connection error: desc = “transport: Error while dialing dial tcp 127.0.0.1:7233: connect: connection refused”

To create the worker container I added in the docker-compose.yml a new service for the hello world project

version: '3.5'
services:
 hello-world-worker:
  image: 'hello-world-worker:latest'
  restart: always
  depends_on:
   - temporal
 cassandra:
  image: cassandra:3.11
  ports:
   - '9042:9042'
 temporal:
  image: temporalio/auto-setup:${SERVER_TAG:-1.3.2}
  ports:
   - '7233:7233'
  volumes:
   - ${DYNAMIC_CONFIG_DIR:-../config/dynamicconfig}:/etc/temporal/config/dynamicconfig
  environment:
   - 'CASSANDRA_SEEDS=cassandra'
   - 'DYNAMIC_CONFIG_FILE_PATH=config/dynamicconfig/development.yaml'
  depends_on:
   - cassandra
 temporal-admin-tools:
  image: temporalio/admin-tools:${SERVER_TAG:-1.3.2}
  stdin_open: true
  tty: true
  environment:
   - 'TEMPORAL_CLI_ADDRESS=temporal:7233'
  depends_on:
   - temporal
 temporal-web:
  image: temporalio/web:${WEB_TAG:-1.3.0}
  environment:
   - 'TEMPORAL_GRPC_ENDPOINT=temporal:7233'
   - 'TEMPORAL_PERMIT_WRITE_API=true'
  ports:
   - '8088:8088'
  depends_on:
   - temporal

With the Dockerfile

FROM golang:alpine
ENV GO111MODULE=on \
 CGO_ENABLED=0 \
 GOOS=linux \
 GOARCH=amd64
WORKDIR /home/hello-world/app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go run ./start/main.go

I also tried to set the same network on temporal and the hello-world project but it did not fix the error.
I don’t know what I’m missing and why the worker can’t connect with temporal

1 Like

Just adding another image to the docker-compose setup will not work because addressability is different within a docker container. Do you need to run the worker in a docker container?

To be clear, the real issue here is that the default connection string workers use will likely not reach your Temporal server endpoint (because of the docker). Your options are to use network (which you said didn’t work), use host network for both containers, or not run the worker inside a docker.

Yes I want my worker to run in a container.
I know the addressability is different within a docker container but I thought using docker-compose will help because all the container would be in the same default network and would communicate easily.

I worked around the problem by setting the client’s “HostPort” with my server IP.

Another solution is to use host network for your services:
Just add:

network_mode: host

to each service inside docker-compose.yml file