'Cloud Run deploy failing when using --command flag
I am trying to deploy to cloud run using it's --command flag option (see https://cloud.google.com/sdk/gcloud/reference/run/deploy) but it fails anytime I try it. I do not know if I am not understanding how to use it or if it is something happening in google cloud's side.
My Dockerfile looks like the following:
FROM python:3.10-slim
ENV PYTHONUNBUFFERED True
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./
RUN pip install --no-cache-dir -r requirements.txt
ENTRYPOINT ["python"]
CMD ["main.py"]
And I am deploying it with:
gcloud run deploy \
$SERVICE \
--image $IMAGE \
--allow-unauthenticated \
--memory $MEMORY \
--concurrency $CONCURRENCY \
--cpu $CPU \
--platform managed \
--region $REGION \
--command "main2.py"
The logs are as follows:
X Deploying... Internal error occurred while performing container health check.
- Creating Revision...
. Routing traffic...
✓ Setting IAM Policy...
Aborted by user.
ERROR: (gcloud.run.deploy) Aborted by user.
Y tried also using only CMD in the Dockerfile (replace 2 last lines with CMD python main.py) and using --command "python main2.py" without success. I want to use the same Docker image but being able to deploy to run main.py (as default in Dockerfile) or main2.py
Note that if the --command flag is omitted it is deployed successfully and the app works.
The test code is at https://github.com/charlielito/cloud-run-test
The python code is just a dummy flask server. The main2.py is the same for testing purposes, just changed the response string.
import os
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
name = os.environ.get("NAME", "World")
return "Hello {}!".format(name)
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=int(os.environ.get("PORT", 8080)))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
