Project: KICS (Provisioning / Security & Compliance)
File: 8a301064-c291-4b20-adcb-403fe7fd95fd.md

title: Changing Default Shell Using RUN Command hide: toc: true navigation: true <style> .highlight .hll { background-color: #ff171742; } .md-content { max-width: 1100px; margin: 0 auto; } </style> Query id: 8a301064-c291-4b20-adcb-403fe7fd95fd Query name: Changing Default Shell Using RUN Command Platform: Dockerfile Severity: <span style="color:#ff7213">Medium</span> Category: Best Practices URL: Using the command RUN to override the default shell instead of the SHELL command leads to inefficiencies. It also does not make sense since Docker provides the SHELL command for this exact purpose.<br> ```dockerfile title="Positive test num. 1 - dockerfile file" hl_lines="5" FROM alpine:3.5 RUN apk add --update py2-pip RUN sudo yum install -y bundler RUN yum install RUN ln -sfv /bin/bash /bin/sh COPY requirements.txt /usr/src/app/ RUN pip install --no-cache-dir -r /usr/src/app/requirements.txt COPY app.py /usr/src/app/ COPY templates/index.html /usr/src/app/templates/ EXPOSE 5000 CMD ["python", "/usr/src/app/app.py"] ``` ```dockerfile title="Positive test num. 2 - dockerfile file" hl_lines="5" FROM alpine:3.5 RUN apk add --update py2-pip RUN sudo yum install -y bundler RUN yum install RUN powershell -command COPY requirements.txt /usr/src/app/ RUN pip install --no-cache-dir -r /usr/src/app/requirements.txt COPY app.py /usr/src/app/ COPY templates/index.html /usr/src/app/templates/ EXPOSE 5000 CMD ["python", "/usr/src/app/app.py"] ``` ```dockerfile title="Negative test num. 1 - dockerfile file" FROM alpine:3.5 RUN apk add --update py2-pip RUN sudo yum install -y bundler RUN yum install SHELL ["/bin/bash", "-c"] COPY requirements.txt /usr/src/app/ RUN pip install --no-cache-dir -r /usr/src/app/requirements.txt COPY app.py /usr/src/app/ COPY templates/index.html /usr/src/app/templates/ EXPOSE 5000 CMD ["python", "/usr/src/app/app.py"] ``` ```dockerfile title="Negative test num. 2 - dockerfile file" FROM alpine:3.5 RUN apk add --update py2-pip RUN sudo yum install -y bundler RUN yum install SHELL ["cmd", "/S", "/C"] COPY requirements.txt /usr/src/app/ RUN pip install --no-cache-dir -r /usr/src/app/requirements.txt COPY app.py /usr/src/app/ COPY templates/index.html /usr/src/app/templates/ EXPOSE 5000 CMD ["python", "/usr/src/app/app.py"] ``` ```dockerfile title="Negative test num. 3 - dockerfile file" FROM alpine:3.5 RUN apk add --update py2-pip RUN sudo yum install -y bundler RUN yum install SHELL ["powershell", "-command"] COPY requirements.txt /usr/src/app/ RUN pip install --no-cache-dir -r /usr/src/app/requirements.txt COPY app.py /usr/src/app/ COPY templates/index.html /usr/src/app/templates/ EXPOSE 5000 CMD ["python", "/usr/src/app/app.py"] ``` <details><summary>Negative test num. 4 - dockerfile file</summary> ```dockerfile FROM alpine:3.5 RUN apk add --update py2-pip RUN sudo yum install -y bundler RUN yum install SHELL ["/bin/sh", "-c"] COPY requirements.txt /usr/src/app/ RUN pip install --no-cache-dir -r /usr/src/app/requirements.txt COPY app.py /usr/src/app/ COPY templates/index.html /usr/src/app/templates/ EXPOSE 5000 CMD ["python", "/usr/src/app/app.py"] ``` </details>