I got an issue where Docker could not find files listed in .gitignore.
For example, my directory structure looks like this:
- project_folder
- WebServer.py
- DockerFile
- config
- privateKey.json
I added config/ to .gitignore file to protect the private key, but I got FileNotFoundError: [Errno 2] No such file or directory: config/privateKey.json error when deploying my project with gcloud run deploy. The error went away if I deleted config/ from .gitignore.
Is there a way to solve this issue and keep config/ in .gitignore?
Thanks!
Here is my DockerFile:
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.10-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 --no-cache-dir -r requirements.txt
# 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.
# Timeout is set to 0 to disable the timeouts of the workers to allow Cloud Run to handle instance scaling.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 "WebServer:create_app()"
My dockerignore
Dockerfile
README.md
*.pyc
*.pyo
*.pyd
__pycache__
.pytest_cache
weight_upload_workflow.py
.git
.gitignore
The gcloud topic
gcloudignoredocumentation includes:So it is possible that adding
config/to.gitignorewould end up preventing its upload due to the generated.gcloudignoreBMitch points out in the comments to
gloud run deploy --source: