Reputation: 191
I am following the Google documentation to upload my docker file into the cloud console:
https://cloud.google.com/run/docs/quickstarts/build-and-deploy#python_1
I changed the main.py
file to my own app.py
which uses Flask. My local Dockerfile is defined as:
# Copyright 2020 Google, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# [START cloudrun_helloworld_dockerfile]
# [START run_helloworld_dockerfile]
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.9-slim
# Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONUNBUFFERED True
# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./
# Install production dependencies.
RUN pip install Flask gunicorn
# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app
ENTRYPOINT ["app.py"]
# [END run_helloworld_dockerfile]
# [END cloudrun_helloworld_dockerfile]
I am not sure if ENTRYPOINT
is need but without it the service does nothing, complains about not main.py
has been found. I can upload the image to the Cloud Run usinggcloud builds submit --tag gcr.io/projectid/webhook
, but the deployment will fail both using gcloud console or locally. The error says:
Invalid ENTRYPOINT. [\
name: "gcr.io/projectid/webhook@sha256:706cd97430e6537f91b0ac8c67262ba6a0c10f961c04a4d918ea1649bcead4e3" \
error: "Invalid command \"app.py\": \
file not found anywhere in PATH \"/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"" ].
Why is the file not found? I thought the Dockerfile will instruct to copy everything in the local directory.
Upvotes: 2
Views: 3404
Reputation: 191
I have got the application working. I did not use ENTRYPOINT in the end, the default CMD exec gunicorn was sufficient. The mistake I have made was the same line, the final argument was main:app, which specifies the variable app in the main.py. I have named my script app.py, so it was complaining it was not found. After fixing the issue the error is solved.
Upvotes: 1
Reputation: 855
It is helpful to know the difference between the RUN
, CMD
and ENTRYPOINT
commands as they run at different times during the container build.
RUN
The RUN
command(s) executes in a new layer and creates a new image, for example, to install software packages. The command runs on top of the current image and creates a new layer by committing the results. Often you will find multiple RUN
instructions in a Dockerfile.
CMD
The CMD
sets a default command or parameters, which can be overwritten from the command line when docker container runs. If a Docker container has a CMD
command, only the last CMD
instruction executes and the default ignored.
ENTRYPOINT
The ENTRYPOINT
configures a container that will run as an executable. It appears similar to CMD
, but the main difference is ENTRYPOINT
is NOT ignored when the Docker container runs.
Upvotes: 1