Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash brace expansion not working on Dockerfile RUN command

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?

like image 555
Ates Goral Avatar asked Oct 20 '16 21:10

Ates Goral


2 Answers

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" ]
like image 62
Ates Goral Avatar answered Oct 07 '22 13:10

Ates Goral


If /bin/bash is available in your image, you can change the shell that the docker build system uses to execute your RUN command, like this:

SHELL ["/bin/bash", "-c"]

Now, your RUN command should work unchanged.

like image 31
user14391097 Avatar answered Oct 07 '22 12:10

user14391097