我遇到了 Docker 找不到 .gitignore 中列出的文件的问题。
例如我的目录结构是这样的:
- project_folder
- WebServer.py
- DockerFile
- config
- privateKey.json
我在
config/
文件中添加了 .gitignore
以保护私钥,但是在使用 FileNotFoundError: [Errno 2] No such file or directory: config/privateKey.json
部署我的项目时出现了 gcloud run deploy
错误。如果我从 .gitignore.中删除
config/
,错误就消失了
有没有办法解决这个问题,让
config/
保持在.gitignore
?
谢谢!
这是我的 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()"
我的 dockerignore
Dockerfile
README.md
*.pyc
*.pyo
*.pyd
__pycache__
.pytest_cache
weight_upload_workflow.py
.git
.gitignore
使用
. 部署我的项目时gcloud run deploy
gcloudignore
文档包括:
生成的
文件默认内容如下:.gcloudignore
--ignore-file
因此,将
.gcloudignore
.git
.gitignore
添加到
config/
可能会由于生成的 .gitignore
而最终阻止其上传