Skip to main content

Shell expansion in your Dockerfile

This blog post might be outdated!
This blog post was published more than one year ago and might be outdated!
· One min read
Stephan Hochdörfer
Head of IT Business Operations

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