Dockerfile构建在ADD上生成lstat错误 [英] Dockerfile build yielding lstat error on ADD

查看:357
本文介绍了Dockerfile构建在ADD上生成lstat错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a dead-simple project with the following structure:

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

json文件的内容:

The contents of the json file:

{
  "setting": "value"
}

Dockerfile的内容:

The contents of the 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 的工作。任何人都可以解释吗?

Why is this failing? Why is it that the not-found item is testapp/config.json? In the past I've used this exact construct to, for instance, copy requirements.txt files into temporary working directories. I don't understand what I'm missing about how ADD works that is causing this to fail. Can anyone explain?

推荐答案

我成为我的IDE的牺牲品。该行将失败:

I fell victim to my IDE. This line will fail:

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

但这将成功:

ADD src/config.json /testapp/config.json

阅读文档添加,它似乎试图使用配置作为目标目录,因此 /testapp/config.json 被视为源文件。 IDE将灰色的#Config ,让我认为它被视为一个评论:Dockerfiles不做内联评论。

Reading the documentation for add, it appears it's trying to use Config as the destination directory, and as such /testapp/config.json is treated as a source file. The IDE greyed out the # Config, making me think it was being treated as a comment: Dockerfiles do not do inline comments.

关于评论的Docker文档, / p>

This is covered in Docker documentation on 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.

这篇关于Dockerfile构建在ADD上生成lstat错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆