【问题标题】:Google cloud or Docker not recognizing folder谷歌云或 Docker 无法识别文件夹
【发布时间】:2021-09-07 09:17:02
【问题描述】:

我有一个具有以下结构的项目:

vineetkalghatgi@vinux:~/personal-projects/bertQA_server$ ls
bert-server-env  cloudbuild.yaml  Dockerfile  main.py  mymodel  Procfile  __pycache__  README.md  requirements.txt  target

我的 .dockerignore:

Dockerfile
README.md
*.pyc
*.pyo
*.pyd
__pycache__
.pytest_cache
bert-server-env

这是我的 Dockerfile

FROM tensorflow/tensorflow

# 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
ADD mymodel .
COPY . .

# Install dependencies
RUN apt-get update \
    && apt-get upgrade -y \
    && apt-get autoremove -y \
    && apt-get clean

# Install production dependencies.
RUN pip3 install -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 main:app

我之前只有COPY . . 没有ADD,并注意到“mymodel”文件夹没有被复制。 如果我运行 gcloud build submit . --tag <my-gcr.io-container 我会收到以下错误:

Step 5/9 : ADD mymodel .
ADD failed: file not found in build context or excluded by .dockerignore: stat mymodel: file does not exist

我可以使用docker build 在本地构建映像,没有任何问题。

【问题讨论】:

  • 似乎mymodel 文件夹永远不会到达上下文模型。你有隐藏的 .gcloudignore 文件吗?要验证您可以尝试添加一个步骤来列出构建工作文件夹中的文件 {name: gcr.io/cloud-builders/gcloud, entrypoint: /bin/bash, args: ['-c', 'ls -la' ]}

标签: docker dockerfile gcloud google-cloud-build docker-build


【解决方案1】:

对于gcloud build submit,如果工作目录中有Dockerfile,则不需要cloudbuild.yaml。因为你有一个cloudbuild.yaml,我怀疑它优先。

Q1:cloudbuild.yaml的内容是什么?

Cloud SDK 使用 .gcloudignore 文件来忽略文件,例如上传到 Cloud Build。

Q2:你有.gcloudignore 文件还是.gitignore 文件?

ls -1a(其中 1==one)或 l=小写 L 也会显示隐藏文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-25
    • 1970-01-01
    • 2021-12-10
    • 1970-01-01
    • 2014-07-20
    • 1970-01-01
    相关资源
    最近更新 更多