docker - Simples Dockerfile 从文本文件中读取数据并输出
问题描述
我正在尝试使用以下内容创建一个非常简单的 Dockerfile
FROM scratch
COPY helloworld.txt helloworld.txt
CMD ["helloworld.txt"]
在这里,我想读取文本文件的内容并将其输出,但无法这样做。
解决方案
您可以使用cat
将文件名作为参数的函数。
tomasz@fox:~$ cat some.txt
foo
所以在你的 Dockerfile 中它看起来像:
FROM alpine
COPY helloworld.txt helloworld.txt
CMD cat helloworld.txt
编辑
就像马克在评论中所说的那样,scratch
是一个空图像。我没有发现。基本上,您可能会使用预定义的图像,例如ubuntu
or alpine
。Alpine 非常轻巧,包含cat
.
推荐阅读
- aws-lambda - 将 S3 访问添加到 SAM EFS 示例
- authentication - Exchange 2016 - 端口 587 上的 IMAP/SMTP 身份验证
- swift - 快速在跟踪区域内禁用光标更改
- javascript - 字符串包含和解析的日期对象不能按预期方式工作
- css - 具有更高特异性的材质 UI 覆盖样式
- python - 将 timedelta 添加/减去导入时间
- vue.js - Vue/Vuelidate:根据requiredIf动态显示需要的星号(*)
- javascript - 视频停止播放后,如何创建触发登录页面弹出的事件?
- drools - 在 Drools 规则引擎中使用列表
- javascript - 使用 Javascript 根据当前选择更改样式