Shell expansion in your Dockerfile

Shell expansion in your Dockerfile

Recently I was in the need to create multiple directories at once in my Dockerfile. Using bash as a shell the shell expansion feature comes in handy:

mkdir -p /my/dir/subdir{1,2,3,4}


But using the above statement in a RUN command did not succeed:

RUN mkdir -p /my/dir/subdir{1,2,3,4}


In my attempt to debug the issue I started the docker container by running bash. Typing the command worked fine which was a bit confusing at first. It took me a while to realize that it worked because I started bash and obviously it does not work in the Dockerfile because the RUN command does not make use of bash as a shell.

The fix was simple: Run bash and pass the mkdir command as parameter:

RUN /bin/bash -c "mkdir -p /my/dir/subdir{1,2,3,4}"


Tags: ,

Eintrag von Stephan Hochdörfer am 09.02.2017

comments powered by Disqus