Bash brace expansion not working on Dockerfile RUN command

旧巷老猫 提交于 2019-12-08 15:46:26

问题


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

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.

What could I be doing wrong?


回答1:


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

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)

And also:

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"]

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" ]


来源:https://stackoverflow.com/questions/40164660/bash-brace-expansion-not-working-on-dockerfile-run-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!