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

查看:35
本文介绍了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}" 在/opt/seagull 下创建,而不是进行大括号扩展.

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,Windows默认为cmd/S/C)

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,请使用传入所需 shell 的 exec 形式.例如,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天全站免登陆