dockerhub 构建失败 requirements.txt 未找到

dockerhub build fails requirements.txt not found

我正在为一些 python 包构建一个 Docker 图像,为此我使用 requirements.txt 通过 pip 安装所有 python 包。

我的 GitHub 存储库的子文件夹中有所有 Docker 文件、requirements.txt 和相关 python 脚本。

-> Main repo
---> folder
    --> some python scripts
    --> docker_folder
       --> Dockerfile
       --> requirements.txt
---> some files
---> some files

我已经在本地构建了图像,它运行良好,但是在 Docker Hub 中配置自动构建时,它通过声明 requirements.txt not found 但它找到了 Docker 文件来抛出错误。我通过以下方式更改了 Docker 集线器上构建设置中的 Docker 文件位置:folder/docker_folder/Dockerfile.

我认为主要问题出在构建配置设置上。有什么帮助吗?谢谢。

来自 Docker 构建的集线器的日志文件:

Cloning into '.'...
Warning: Permanently added the RSA host key for IP address '140.82.114.3' to the list of known hosts.
Reset branch 'master'
Your branch is up-to-date with 'origin/master'.
KernelVersion: 4.4.0-1060-aws
Components: [{u'Version': u'19.03.8', u'Name': u'Engine', u'Details': {u'KernelVersion': u'4.4.0-1060-aws', u'Os': u'linux', u'BuildTime': u'2020-03-11T01:24:30.000000000+00:00', u'ApiVersion': u'1.40', u'MinAPIVersion': u'1.12', u'GitCommit': u'afacb8b7f0', u'Arch': u'amd64', u'Experimental': u'false', u'GoVersion': u'go1.12.17'}}, {u'Version': u'1.2.13', u'Name': u'containerd', u'Details': {u'GitCommit': u'7ad184331fa3e55e52b890ea95e65ba581ae3429'}}, {u'Version': u'1.0.0-rc10', u'Name': u'runc', u'Details': {u'GitCommit': u'dc9208a3303feef5b3839f4323d9beb36df0a9dd'}}, {u'Version': u'0.18.0', u'Name': u'docker-init', u'Details': {u'GitCommit': u'fec3683'}}]
Arch: amd64
BuildTime: 2020-03-11T01:24:30.000000000+00:00
ApiVersion: 1.40
Platform: {u'Name': u'Docker Engine - Community'}
Version: 19.03.8
MinAPIVersion: 1.12
GitCommit: afacb8b7f0
Os: linux
GoVersion: go1.12.17
Starting build of index.docker.io/darsh3/python_drl:latest...
Step 1/5 : FROM python:3.8
---> 8f6adb7689b5
Step 2/5 : WORKDIR ${PWD}/..
---> Running in 516d190b493f
Removing intermediate container 516d190b493f
---> e948c6e6f641
Step 3/5 : COPY requirements.txt ./
COPY failed: stat /var/lib/docker/tmp/docker-builder968608568/requirements.txt: no such file or directory

请使用如下的 COPY 命令。发生错误是因为您可能正在使用 . context

构建图像
COPY folder/docker_folder/requirements.txt ./

根据你显示的目录结构,如果你运行

docker build -f folder/docker_folder/Dockerfile "Main repo"

那么所有COPY命令的源都是相对于"Main repo"目录的。

FROM python:3.8
WORKDIR /app
# Needs to COPY from the directory relative to the `docker build`
# context directory argument
COPY folder/docker_folder/requirements.txt .
RUN pip install -r requirements.txt

您可能会考虑将 requirements.txt 文件移动到存储库的顶层或者可能是包含 Python 脚本的目录,因为它是标准的 Python 打包文件而不是Docker-具体。如果你拥有的唯一 Docker-specific 东西是 Dockerfile 那么把它放在顶级目录中也很常见。

# If the Dockerfile is in the named directory, no -f option is needed
docker build "Main repo/folder"
# If the file is in the named directory, just use its name without a path
COPY requirements.txt .