title: Go gRPC on Docker on Cloud Run "transport: Error while dialing dial tcp : i/o timeout""
body: <p>I have a gRPC server</p>
  <pre><code>
  type Server struct {
      name         string
      host         string
      port         string
      dbUser       string
      dbPassword   string
      dbURL        string
      dbParameters string
  }
  
  func main() {
  
      /*Start of config*/
      server := Server{
          &quot;User service&quot;,
          &quot;&quot;,
          os.Getenv(&quot;PORT&quot;),
          &quot;&quot;,
          &quot;&quot;,
          &quot;&quot;,
          &quot;&quot;,
      }
      /*End of config*/
  
      log.Printf(&quot;Starting: %s RPCServer\n&quot;, server.name)
      lis, err := net.Listen(&quot;tcp&quot;, server.host+&quot;:&quot;+server.port)
      if err != nil {
          log.Fatalf(&quot;Failed to liste: %v\n&quot;, err)
      }
      defer func() {
          err = lis.Close()
          if err != nil {
              log.Fatalf(&quot;Failed to close listener: %v\n&quot;, err)
          }
      }()
      gRPCServer := grpc.NewServer()
      ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
      defer cancel()
  
      reg := codecs.Register(bson.NewRegistryBuilder()).Build()
      mongoURI := options.Client().ApplyURI(
          &quot;mongodb+srv://&quot; + server.dbUser + &quot;:&quot; + server.dbPassword + &quot;@&quot; + server.dbURL + server.dbParameters,
      )
  
      mongoClient, err := mongo.NewClient(mongoURI, &amp;options.ClientOptions{
          Registry: reg,
      })
      if err != nil {
          log.Fatalf(&quot;unable to create new mongo clinet: %s\n&quot;, err)
      }
      err = mongoClient.Connect(ctx)
      if err != nil {
          log.Fatalf(&quot;unable to connect to db: %s\n&quot;, err)
      }
  
      /*Start of registering service*/
      authService, err := AuthService.NewAuthService()
      if err != nil {
          log.Fatalf(&quot;unable to create server: %s\n&quot;, err)
      }
      s := UserService.NewServer(authService, mongoClient)
      UserService.RegisterUserServiceServer(gRPCServer, &amp;s)
      /*End of registering service*/
  
      go func() {
          if err := gRPCServer.Serve(lis); err != nil {
              log.Printf(&quot;Failed to serve: %v\n&quot;, err)
          }
      }()
      log.Printf(&quot;server successfully started on port: %s\n\n&quot;, server.port)
      c := make(chan os.Signal)
      signal.Notify(c, os.Interrupt)
      &lt;-c
      log.Printf(&quot;\nstopping server...\n&quot;)
      gRPCServer.Stop()
      err = lis.Close()
      if err != nil {
          log.Fatalf(&quot;failed to close listner: %s\n&quot;, err)
      }
      err = mongoClient.Disconnect(ctx)
      if err != nil {
          log.Fatalf(&quot;failed to disconnect from mongodb: %s\n&quot;, err)
      }
      log.Printf(&quot;successfully closed server\n&quot;)
  }
  
  </code></pre>
  <p>And my Dockerfile is</p>
  <pre><code>FROM golang:alpine AS build-env
  WORKDIR /app
  ADD . /app
  RUN cd /app &amp;&amp; go build Main/server.go
  
  FROM alpine
  RUN apk update &amp;&amp; apk add ca-certificates &amp;&amp; rm -rf /var/cache/apk/*
  WORKDIR /app
  COPY --from=build-env /app/server /app
  COPY --from=build-env /app/Config/* /app
  ENV GOOGLE_APPLICATION_CREDENTIALS=cred.json
  
  EXPOSE 50051
  CMD [&quot;./server&quot;]
  </code></pre>
  <p>I put up the docker image on Google Container Registry, and tried to use Cloud Run to run it using the following command</p>
  <pre><code>gcloud run deploy grpc-server-streaming\
            --project=project-id\
            --platform=managed\
            --region=asia-south1\
            --image=image-tag\
            --allow-unauthenticated
  </code></pre>
  <p>After which I went into Cloud Run application and enabled HTTP/2 connections. But am still not able to connect to the service. I get the following error</p>
  <pre><code>2021/04/21 17:04:36 rpc error: code = Unavailable desc = upstream connect error or disconnect/reset before headers. reset reason: connection termination
  </code></pre>
  <p>I've been stuck at this for two days and am not sure what to do.</p>