Bash大括号扩展不适用于Dockerfile RUN命令 [英] Bash brace expansion not working on Dockerfile RUN command

查看:172
本文介绍了Bash大括号扩展不适用于Dockerfile RUN命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Dockerfile中运行以下RUN命令,期望在每个列出的子目录下创建一个日志目录:

I'm running the following RUN command in my Dockerfile, expecting a "logs" directory to be created under each of the listed subdirectories:

RUN mkdir -p /opt/seagull/{diameter-env,h248-env,http-env,msrp-env,octcap-env,radius-env,sip-env,synchro-env,xcap-env}/logs

但是,当我检查图像时,我看到一个目录,其名称为 {diameter-env ,h248-env,http-env,msrp-env,octcap-env,radius-env,sip-env,synchro-env,xcap-env}创建,而不是进行括号扩展。

But when I check the image, I see a directory literally called "{diameter-env,h248-env,http-env,msrp-env,octcap-env,radius-env,sip-env,synchro-env,xcap-env}" created under /opt/seagull, instead of brace expansion taking place.

我在做什么错了?

推荐答案

您没有使用大括号扩展,因为您没有使用Bash。如果您查看有关RUN命令的文档

You're not using brace expansion, because you're not using Bash. If you look at the documentation for the RUN command:


RUN(shell形式,该命令在shell中运行,默认情况下在Linux上为/ bin / sh -c或在Linux上使用cmd / S / C Windows)

RUN (shell form, the command is run in a shell, which by default is /bin/sh -c on Linux or cmd /S /C on Windows)

而且:


注意:要使用'/ bin / sh'以外的其他shell,请使用exec形式传入所需的shell。例如,RUN [ / bin / bash,-c, echo hello]

Note: To use a different shell, other than ‘/bin/sh’, use the exec form passing in the desired shell. For example, RUN ["/bin/bash", "-c", "echo hello"]

因此,只需更改命令来使用exec表单并显式使用Bash shell:

So, just change the command to use the exec form and explicitly use a Bash shell:

RUN [ "/bin/bash", "-c", "mkdir -p /opt/seagull/{diameter-env,h248-env,http-env,msrp-env,octcap-env,radius-env,sip-env,synchro-env,xcap-env}/logs" ]

这篇关于Bash大括号扩展不适用于Dockerfile RUN命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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