我正在尝试自动化码头形象的建设。假设在一个目录中,有几个Dockerfile文件。其中一些文件被命名为Dockerfile.test或Dockerfile_node,因为一个目录中有多个文件,而且不能全部命名为Dockerfile。
我有一个简单的脚本,它定位所有这些文件,并需要调用docker构建。
这是我用来定位所有Dockerfile的命令。
list=$(find . -name "Dockerfile*")我得到了以下清单:
./Dockerfile1
./testing/Dockerfile
./testing/Dockerfile_kubernetes为了获得上下文,我需要找到包含Dockerfile文件的目录。
files=$(find . -name "Dockerfile*" -exec dirname {} \;)对于每个Dockerfile,我都调用docker build。就像这样..。
for x in $files; do docker build $x; done;我无法执行docker build,因为我得到了以下错误。
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/ubuntu/repo/Dockerfile: no such file or directory运行docker build命令将只生成在./testing/Dockerfile中定义的映像。
我知道在一个目录中有多个Dockerfile文件是不好的做法,并且像这样命名它们,但我不是做出这些决定的人。我只需要让它发挥作用。
有办法构建这些Dockerfile吗?
发布于 2022-04-04 10:25:55
您需要传递docker文件名才能生成命令。
for x in $files; do docker build -f $x .; done;默认情况下,
构建命令将在构建上下文的根处查找Dockerfile。-f --file选项允许您指定要使用的替代文件的路径
https://stackoverflow.com/questions/71735538
复制相似问题