Hello ,
i am new to temporal and trying to understand it by running some examples.
i decided to take things further by packaging a temporal app as a docker image. i have a temporal server running on the host which i setup using docker compose from temporal github and the server works fine. i can access it on port 8088. the problem begins when i try to build my image, to enable communication with my server i use sudo docker build --network=host -t name .
below is my Dockerfile
> FROM golang:alpine
> ENV GO111MODULE=on \
> CGO_ENABLED=0 \
> GOOS=linux \
> GOARCH=amd64
> # Set the Current Working Directory inside the container
> WORKDIR /app
> COPY go.mod ./
> COPY go.sum ./
> # Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
> RUN go mod download
> RUN go mod tidy
> # Copy the source from the current directory to the Working Directory inside the container
> COPY . ./
> #RUN go run ./worker/main.go
> RUN go run ./starter/main.go
When the build gets to the last line which is RUN go run ./starter/main.go
it freezes there and i have to restart my server.
Please any help will be appreciated.
Hard to tell as don’t know what your starter code does.
By default when you start a new client like client.NewClient(client.Options{})
it has the HostPort flag set to connect to the frontend service at “localhost:7233”. If your deployed frontend service is exposed on a different host/port you need to set that in your code, for example:
c, err := client.NewClient(client.Options{
HostPort: "...",
})
note the value is passed directly to gRPC so should have following formats: GRPC Core: gRPC Name Resolution
hope this helps
Hello @tihomir thanks for the response. i am not connecting on a different port.
my starter code below, it prints a message
package main
import (
"context"
"log"
"github.com/wafi/hello-workflow/helloworkflow"
"go.temporal.io/sdk/client"
)
func main() {
c, err := client.NewClient(client.Options{})
if err != nil {
log.Fatalln("Unable to make client", err)
}
defer c.Close()
workflowOptions := client.StartWorkflowOptions{
TaskQueue: "hello-world",
}
we, err := c.ExecuteWorkflow(context.Background(), workflowOptions, helloworkflow.Workflow, "victor")
if err != nil {
log.Fatalln("Unable to execute workflow", err)
}
var result string
// store the result of the run
err = we.Get(context.Background(), &result)
if err != nil {
log.Fatalln("Unable to get workflow result", err)
}
log.Println("workflow result:", result)
}
i wonder if i am building the image wrong
Not a docker expert, seems tho that you are missing the compile part in your docker file, for example:
RUN go build -o /my-app-name
This might help - Build your Go image | Docker Documentation
@tihomir thanks i have resolved the build issue, sorry for taking so long to post here
here’s the my dockerfile below
# syntax=docker/dockerfile:1
FROM golang:1.16-alpine
WORKDIR /app/
COPY . .
RUN go build -o ./main
CMD ["./main" ]