【问题标题】:Simples Dockerfile to read data from text file and outputSimples Dockerfile 从文本文件中读取数据并输出
【发布时间】:2018-05-04 12:20:34
【问题描述】:

我正在尝试使用以下内容创建一个非常简单的 Dockerfile

FROM scratch
COPY helloworld.txt helloworld.txt
CMD ["helloworld.txt"]

这里我想读取文本文件的内容并输出,但不能这样做。

【问题讨论】:

    标签: docker dockerfile


    【解决方案1】:

    您可以使用cat 函数,该函数将文件名作为参数。

    tomasz@fox:~$ cat some.txt
    foo
    

    所以在你的 Dockerfile 中它看起来像:

    FROM alpine
    COPY helloworld.txt helloworld.txt
    CMD cat helloworld.txt
    

    编辑

    就像 Mark 在评论中所说,scratch 是一个空图像。我没有发现。基本上,您可能会使用预定义的图像,例如 ubuntualpine。 Alpine 非常轻量级,包含cat

    【讨论】:

    • 你没有cat在scratch中,scratch是空的。您需要在 Dockerfile 中使用 Linux 父映像并使用 cat,或者如果您想使用暂存器,则需要编写和编译可以在空映像中独立运行的二进制文件并使用它打印 txt 文件。
    • 感谢您的回复。我现在明白了。但由于我在 Windows 和命令提示符中,我可以使用记事本 helloworld.txt 之类的东西来打开 helloworld.txt 文件吗?
    猜你喜欢
    • 1970-01-01
    • 2016-11-20
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多