简体   繁体   中英

Running go program on Google Cloud Run without listening for incoming HTTP requests

I wrote a Go program which doesn't need to retrieve external http calls at all by default. I tried to deploy it on Google Cloud Run and received the following error:

The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable. Logs for this revision might contain more information.

I understand it happens because my code doesn't provide a port. As this answer states:

container must listen for incoming HTTP requests on the port that is defined by Cloud Run and provided in the $PORT environment variable

My question is what can I do if wouldn't like define any ports and just want to run the same code I run locally? Is there an alternate solution to deploy my code without it, or I must add it anyway if I want run the code from Cloud Run?

For containers that do not require an HTTP listener (HTTP server), use Cloud Run Jobs.

  • Cloud Run Jobs is in preview.
  • Your Go program must exit with exit code 0 for success and non-zero for failure.
  • Your container should not listen on a port or start a web server.
  • Environment variables are different from Cloud Run.
  • Container instances run until the container instance exits, until the task timeout is reached, or until the container crashes. Task timeout default is 10 minutes, max is one hour.

Cloud Run - Create jobs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM