简体   繁体   中英

Set Google Cloud Run environment variables value based on another environment variable

As far as I understand Google Cloud Run sets a $PORT environment variable by itself that my application should try to run on. Let's say my application wants to start on $PORT2 . Can I define on the Google Cloud Run Environment Variables page (or elsewhere) that $PORT2 envvar should take the value of $PORT ? Obviously the other solution would be to change my application start on PORT , am just curious if this is possible? Thanks

You can pretty much only achieve it by changing your container's entrypoint to a program (eg env ) that re-adjusts the environment variables to your program:

ENTRYPOINT ["/bin/sh", "-c", "env PORT2=$PORT ./your-app"]

Try it:

docker run --rm -e PORT=8080 busybox /bin/sh -c 'env PORT2=$PORT env'

+1

Example of use case: one docker image that has two targets used by two containers (an API server and a worker)

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