Wednesday, August 05, 2015

Use 'set -x' in to debug docker multiline statements or docker invoked bash scripts

Some people new to Docker are also new to bash which is a must-have skill for *nix sysadmin. Perhaps the most important statement for bash debugging is 'set -x'. If you have multiline statement, use it to understand where exactly the whole RUN command is failing. The classical example involves entering a directory and issuing there several commands. Without 'set -x' you will be lost about why and in some cases even what specific command failed. Example:
RUN set -x \
      cd /tmp \
Another example involves calling an external script. In that case you just need to make sure the flag is included through sed, for example let us say you use the 'bash -e' in your shebang (aren't you?). To change the shebang on the fly is as easy as:
RUN sed -i 's/bash -e/bash -ex/g' /some/bash/

No comments: