3

I have an application in dockerfile where it is necessary to call a .sh file to download packages, but there is always an error when calling this file.

My dockerfile is:

FROM alpine:3.12 as builder

ARG VERSION=7.16.0
ARG DISTRO=tomcat
ARG SNAPSHOT=true

ARG JMX_PROMETHEUS_VERSION=0.12.0

RUN apk add --no-cache \
        bash \
        ca-certificates \
        maven \
        tar \
        wget \
        xmlstarlet

COPY settings.xml download.sh camunda-run.sh camunda-tomcat.sh camunda-wildfly.sh  /tmp/

RUN /tmp/download.sh

FROM alpine:3.12

RUN apk add --no-cache \
        bash \
        ca-certificates \
        curl \
        openjdk11-jre-headless \
        tzdata \
        tini \
        xmlstarlet \
    && curl -o /usr/local/bin/wait-for-it.sh \
      "https://raw.githubusercontent.com/vishnubob/wait-for-it/a454892f3c2ebbc22bd15e446415b8fcb7c1cfa4/wait-for-it.sh" \
    && chmod +x /usr/local/bin/wait-for-it.sh

RUN addgroup -g 1000 -S camunda && \
    adduser -u 1000 -S camunda -G camunda -h /camunda -s /bin/bash -D camunda
WORKDIR /camunda
USER camunda

ENTRYPOINT ["/sbin/tini", "--"]
CMD ["./camunda.sh"]

COPY --chown=camunda:camunda --from=builder /camunda .

My download.sh file looks exactly like this: https://github.com/camunda/docker-camunda-bpm-platform/blob/next/download.sh

When running the command: docker build . -t servicecamundadocker/latest i get the error:

 => ERROR [builder 4/4] RUN /tmp/download.sh                                                                                       0.2s ------
 > [builder 4/4] RUN /tmp/download.sh:
#11 0.216 /bin/sh: illegal option -
------

enter image description here

Does anyone know how to fix this error? Thanks

4
  • the default shell for alpine is ash (although /bin/sh might be an alias for that) so maybe the -ex used in that script is not supported ... Can you try to execute that script in a interactive plain alpine container ? Sep 4, 2021 at 13:37
  • 2
    can you add the download.sh script contents? Sep 4, 2021 at 14:29
  • 1
    @Noam Yizraeli done! Sep 4, 2021 at 15:26
  • in your script you start with /bin/sh -ex, -e exits when not in interactive mode (it says in the docs that - If not interactive, exit immediately if any untested command fails) can you remove it and try again? Sep 4, 2021 at 15:31

1 Answer 1

16

After a lot of research, I found the solution.

The problem is that Windows uses \r\n as an end of line, whereas unix only uses \n. So, inside my download.sh file, there was a ^M character that led to the error /bin/sh: illegal option

The solution was to copy the code from the downlod.sh file and convert it to LF:

  • Use the text editor such as Notepad++ at the Windows machine to convert
    • Go to menu Edit -> EOL Conversion -> Unix (LF)

Once that is done, the docker build works correctly.

Thank you all for the support.

3
  • 1
    for those that vi/vim use :set ff=unix. Sep 9, 2021 at 23:43
  • 1
    thank you, good sir!
    – srt
    Oct 25, 2021 at 16:58
  • or a .gitattributes with *.sh text eol=lf
    – Sandburg
    Mar 19 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.