Cannot use process substitution during docker build because bash goes into posix mode

In a Dockerfile, I want to use process substitution:

RUN echo <(echo '$DATA:'"$DATA")

But docker build runs every RUN command with /bin/sh. Apparently being run as sh causes bash to switch to POSIX mode, which does not allow process substitution:

  • Building a docker image using AWS Developer Tools
  • PyCharm add remote Python interpreter inside the Docker
  • executing mysql script docker
  • How to Bootstrap from Workstaion to Docker conatiner?
  • How to stop all containers when one container stops with docker-compose?
  • Add yaml parse to php.ini file using docker
  • /bin/sh: -c: line 0: syntax error near unexpected token `('

    I tried switching off POSIX mode:

    RUN set +o posix && echo <(echo '$DATA:'"$DATA")

    But it seems the syntax error happens even before the first command is run. Same if I replace && with ;.

    Note that the command (even the one that I used as a simplified example here) contains both single and double quotes, so I can’t simply prepend bash -c.

    The used shell is actually a bash, but it is invoked as /bin/sh by docker:

    Step 7 : RUN ls -l /bin/sh
    ---> Running in 93a9809e12a7
    lrwxrwxrwx    1 root     root             9 Dec 28 03:38 /bin/sh -> /bin/bash

  • Docker + nginx + PHP - nginx does not point to the root directory?
  • Start Docker container with random host port and return the port to use it elsewhere
  • How to use Nginx to connect to my app in Docker image?
  • Determine if new docker container available on docker hub
  • hotdeploy / hotswap classes using wildfly maven docker intellij
  • Docker tomcat WARNING: Unable to load server configuration from [/usr/local/tomcat/conf/server.xml]
  • One Solution collect form web for “Cannot use process substitution during docker build because bash goes into posix mode”

    Assuming your sh is not bash, you can’t use process substitution in shell mode directly; you need to spawn a bash session (non-login, non-interactive here):

    RUN [ "/bin/bash", "-c", "echo <(echo '$DATA:'\"$DATA\")" ]

    Here i have used the json (aka exec) form to make sure the quotes are easily managed, here you just need to escape quotes around $DATA: \"$DATA\" — to prevent json interpretation beforehand.

    If your sh is in fact bash, this should do:

    RUN "echo <(echo '$DATA:'"$DATA")"

    Also this just outputs the file descriptor, i am not rally sure about your plan.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.