首页 > 解决方案 > Simples Dockerfile 从文本文件中读取数据并输出

问题描述

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

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

在这里,我想读取文本文件的内容并将其输出,但无法这样做。

标签: dockerdockerfile

解决方案


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

tomasz@fox:~$ cat some.txt
foo

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

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

编辑

就像马克在评论中所说的那样,scratch是一个空图像。我没有发现。基本上,您可能会使用预定义的图像,例如ubuntuor alpine。Alpine 非常轻巧,包含cat.


推荐阅读