gpt4 book ai didi

docker - Dockerfile构建在ADD上产生lstat错误

转载 作者:行者123 更新时间:2023-12-02 19:09:50 25 4
gpt4 key购买 nike

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

docker/
|- src/
| |- config.json
|
|- Dockerfile

json文件的内容:
{
"setting": "value"
}

Dockerfile的内容:
FROM python:3.5

ADD src/config.json /testapp/config.json # Config

我运行以下构建命令:
docker build -t testapp:dev .

并得到以下结果:
Sending build context to Docker daemon 4.608 kB
Step 1 : FROM python:3.5
---> 1d0326469b55
Step 2 : ADD src/config.json /testapp/config.json
lstat testapp/config.json: no such file or directory

为什么会失败?为什么找不到的项目是 testapp/config.json?过去,我曾使用这种精确的结构将 requirements.txt文件复制到临时工作目录中。我不了解关于 ADD的工作方式而导致失败的原因。谁能解释?

最佳答案

我成为IDE的受害者。该行将失败:

ADD src/config.json /testapp/config.json  # Config

但这将成功:
ADD src/config.json /testapp/config.json

读取 documentation进行添加时,似乎正在尝试将 Config用作目标目录,因此 /testapp/config.json被视为源文件。 IDE使 # Config变灰,使我认为它被视为注释:Dockerfiles不做内联注释。

comments的Docker文档中对此进行了介绍:

Docker will treat lines that begin with # as a comment. A # marker anywhere else in the line will be treated as an argument.

关于docker - Dockerfile构建在ADD上产生lstat错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41642784/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com