Docker image openjdk:8-jdk-alpine fails to execute a simple command











up vote
0
down vote

favorite












I created a docker image from openjdk:8-jdk-alpine using the below Dockerfile:



Dockerfile



But when I try to execute simple commands I get the following errors:



/bin/sh: ./run.sh: not found


my run.sh looks like this
enter image description here
I try to "docker run -it [images] bash" enter to the interactive environment,I can see the file "run.sh".In the directory /bin bash exist,but I execute run.sh also display " /bin/sh: ./run.sh: not found"



PS:Sorry for my poor english,I am a chinese student










share|improve this question
























  • try changing ADD to COPY
    – lependu
    Nov 20 at 14:43






  • 1




    How does you run.sh look like?
    – vstm
    Nov 20 at 15:06






  • 1




    I did not manage to reproduce the problem. I suggest you try again with a simpler Dockerfile that includes a simple run.sh (something that just echos some text, for example). If you can reproduce - update here, otherwise - try to work towards your requirements and see where it breaks.
    – Guss
    Nov 20 at 15:08










  • Try ADD run.sh to a specific directory. For example ADD run.sh /tmp/run.sh and then change your CMD to CMD /run.sh
    – Josemy
    Nov 20 at 15:39










  • just add CMD ["/run.sh"] instead
    – Innocent Anigbo
    Nov 20 at 16:58















up vote
0
down vote

favorite












I created a docker image from openjdk:8-jdk-alpine using the below Dockerfile:



Dockerfile



But when I try to execute simple commands I get the following errors:



/bin/sh: ./run.sh: not found


my run.sh looks like this
enter image description here
I try to "docker run -it [images] bash" enter to the interactive environment,I can see the file "run.sh".In the directory /bin bash exist,but I execute run.sh also display " /bin/sh: ./run.sh: not found"



PS:Sorry for my poor english,I am a chinese student










share|improve this question
























  • try changing ADD to COPY
    – lependu
    Nov 20 at 14:43






  • 1




    How does you run.sh look like?
    – vstm
    Nov 20 at 15:06






  • 1




    I did not manage to reproduce the problem. I suggest you try again with a simpler Dockerfile that includes a simple run.sh (something that just echos some text, for example). If you can reproduce - update here, otherwise - try to work towards your requirements and see where it breaks.
    – Guss
    Nov 20 at 15:08










  • Try ADD run.sh to a specific directory. For example ADD run.sh /tmp/run.sh and then change your CMD to CMD /run.sh
    – Josemy
    Nov 20 at 15:39










  • just add CMD ["/run.sh"] instead
    – Innocent Anigbo
    Nov 20 at 16:58













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I created a docker image from openjdk:8-jdk-alpine using the below Dockerfile:



Dockerfile



But when I try to execute simple commands I get the following errors:



/bin/sh: ./run.sh: not found


my run.sh looks like this
enter image description here
I try to "docker run -it [images] bash" enter to the interactive environment,I can see the file "run.sh".In the directory /bin bash exist,but I execute run.sh also display " /bin/sh: ./run.sh: not found"



PS:Sorry for my poor english,I am a chinese student










share|improve this question















I created a docker image from openjdk:8-jdk-alpine using the below Dockerfile:



Dockerfile



But when I try to execute simple commands I get the following errors:



/bin/sh: ./run.sh: not found


my run.sh looks like this
enter image description here
I try to "docker run -it [images] bash" enter to the interactive environment,I can see the file "run.sh".In the directory /bin bash exist,but I execute run.sh also display " /bin/sh: ./run.sh: not found"



PS:Sorry for my poor english,I am a chinese student







java docker






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 3:06

























asked Nov 20 at 14:42









user10680765

11




11












  • try changing ADD to COPY
    – lependu
    Nov 20 at 14:43






  • 1




    How does you run.sh look like?
    – vstm
    Nov 20 at 15:06






  • 1




    I did not manage to reproduce the problem. I suggest you try again with a simpler Dockerfile that includes a simple run.sh (something that just echos some text, for example). If you can reproduce - update here, otherwise - try to work towards your requirements and see where it breaks.
    – Guss
    Nov 20 at 15:08










  • Try ADD run.sh to a specific directory. For example ADD run.sh /tmp/run.sh and then change your CMD to CMD /run.sh
    – Josemy
    Nov 20 at 15:39










  • just add CMD ["/run.sh"] instead
    – Innocent Anigbo
    Nov 20 at 16:58


















  • try changing ADD to COPY
    – lependu
    Nov 20 at 14:43






  • 1




    How does you run.sh look like?
    – vstm
    Nov 20 at 15:06






  • 1




    I did not manage to reproduce the problem. I suggest you try again with a simpler Dockerfile that includes a simple run.sh (something that just echos some text, for example). If you can reproduce - update here, otherwise - try to work towards your requirements and see where it breaks.
    – Guss
    Nov 20 at 15:08










  • Try ADD run.sh to a specific directory. For example ADD run.sh /tmp/run.sh and then change your CMD to CMD /run.sh
    – Josemy
    Nov 20 at 15:39










  • just add CMD ["/run.sh"] instead
    – Innocent Anigbo
    Nov 20 at 16:58
















try changing ADD to COPY
– lependu
Nov 20 at 14:43




try changing ADD to COPY
– lependu
Nov 20 at 14:43




1




1




How does you run.sh look like?
– vstm
Nov 20 at 15:06




How does you run.sh look like?
– vstm
Nov 20 at 15:06




1




1




I did not manage to reproduce the problem. I suggest you try again with a simpler Dockerfile that includes a simple run.sh (something that just echos some text, for example). If you can reproduce - update here, otherwise - try to work towards your requirements and see where it breaks.
– Guss
Nov 20 at 15:08




I did not manage to reproduce the problem. I suggest you try again with a simpler Dockerfile that includes a simple run.sh (something that just echos some text, for example). If you can reproduce - update here, otherwise - try to work towards your requirements and see where it breaks.
– Guss
Nov 20 at 15:08












Try ADD run.sh to a specific directory. For example ADD run.sh /tmp/run.sh and then change your CMD to CMD /run.sh
– Josemy
Nov 20 at 15:39




Try ADD run.sh to a specific directory. For example ADD run.sh /tmp/run.sh and then change your CMD to CMD /run.sh
– Josemy
Nov 20 at 15:39












just add CMD ["/run.sh"] instead
– Innocent Anigbo
Nov 20 at 16:58




just add CMD ["/run.sh"] instead
– Innocent Anigbo
Nov 20 at 16:58












1 Answer
1






active

oldest

votes

















up vote
1
down vote













The printed content of the run.sh, indicates that my original assessment was incorrect; however based on the error message, and the image of the run.sh file, I have a lead.



Your run.sh script has an exec line of #!/bin/sh, which means that it does not need bash to operate so my previous assessment was incorrect.



Starting on a mac, I created a run.sh script, duplicated the dockerfile (mostly), and it ran correctly, producing a valid run.



I then converted the run.sh to use dos line endings and got the following:



$ file run.sh
run.sh: POSIX shell script text executable, ASCII text, with CRLF line terminators
$ docker run --rm -it bob
/bin/sh: ./run.sh: not found


Which looks suspiciously like your error message.



From this, it would lead me to believe that your run.sh file contains dos line endings. Based on the images, I'm guessing that you're on windows, which is where the problem with the run.sh script originates.



how to convert the line endings (some examples):




  • dos2unix run.sh

  • perl -pi -e 's/rn/n/g' run.sh


Previous Answer



The most likely reason for this issue is that the shebang line in the run.sh contains: #!/usr/bin/bash, or something of that ilk - i.e. it doesn't reference the valid path to the binary that will run the shell script.



On alpine, bash is installed into /bin, so if you try to run the script you will see the error:



/ # ./run.sh
/bin/sh: ./run.sh: not found
/ # cat run.sh
#!/usr/bin/bash

echo "Hi"


workaround (1): after the apk add bash, do an:



RUN ln -s /bin/bash /usr/bin


in your Dockerfile. This will create a symlink for bash, allowing the program to run:



/ # ln -s /bin/bash /usr/bin
/ # ./run.sh
Hi


workaround(2) - if you don't want to make a symlink like this, you can always invoke bash as part of the CMD -



CMD [ 'bash', './run.sh' ]





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395463%2fdocker-image-openjdk8-jdk-alpine-fails-to-execute-a-simple-command%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    The printed content of the run.sh, indicates that my original assessment was incorrect; however based on the error message, and the image of the run.sh file, I have a lead.



    Your run.sh script has an exec line of #!/bin/sh, which means that it does not need bash to operate so my previous assessment was incorrect.



    Starting on a mac, I created a run.sh script, duplicated the dockerfile (mostly), and it ran correctly, producing a valid run.



    I then converted the run.sh to use dos line endings and got the following:



    $ file run.sh
    run.sh: POSIX shell script text executable, ASCII text, with CRLF line terminators
    $ docker run --rm -it bob
    /bin/sh: ./run.sh: not found


    Which looks suspiciously like your error message.



    From this, it would lead me to believe that your run.sh file contains dos line endings. Based on the images, I'm guessing that you're on windows, which is where the problem with the run.sh script originates.



    how to convert the line endings (some examples):




    • dos2unix run.sh

    • perl -pi -e 's/rn/n/g' run.sh


    Previous Answer



    The most likely reason for this issue is that the shebang line in the run.sh contains: #!/usr/bin/bash, or something of that ilk - i.e. it doesn't reference the valid path to the binary that will run the shell script.



    On alpine, bash is installed into /bin, so if you try to run the script you will see the error:



    / # ./run.sh
    /bin/sh: ./run.sh: not found
    / # cat run.sh
    #!/usr/bin/bash

    echo "Hi"


    workaround (1): after the apk add bash, do an:



    RUN ln -s /bin/bash /usr/bin


    in your Dockerfile. This will create a symlink for bash, allowing the program to run:



    / # ln -s /bin/bash /usr/bin
    / # ./run.sh
    Hi


    workaround(2) - if you don't want to make a symlink like this, you can always invoke bash as part of the CMD -



    CMD [ 'bash', './run.sh' ]





    share|improve this answer



























      up vote
      1
      down vote













      The printed content of the run.sh, indicates that my original assessment was incorrect; however based on the error message, and the image of the run.sh file, I have a lead.



      Your run.sh script has an exec line of #!/bin/sh, which means that it does not need bash to operate so my previous assessment was incorrect.



      Starting on a mac, I created a run.sh script, duplicated the dockerfile (mostly), and it ran correctly, producing a valid run.



      I then converted the run.sh to use dos line endings and got the following:



      $ file run.sh
      run.sh: POSIX shell script text executable, ASCII text, with CRLF line terminators
      $ docker run --rm -it bob
      /bin/sh: ./run.sh: not found


      Which looks suspiciously like your error message.



      From this, it would lead me to believe that your run.sh file contains dos line endings. Based on the images, I'm guessing that you're on windows, which is where the problem with the run.sh script originates.



      how to convert the line endings (some examples):




      • dos2unix run.sh

      • perl -pi -e 's/rn/n/g' run.sh


      Previous Answer



      The most likely reason for this issue is that the shebang line in the run.sh contains: #!/usr/bin/bash, or something of that ilk - i.e. it doesn't reference the valid path to the binary that will run the shell script.



      On alpine, bash is installed into /bin, so if you try to run the script you will see the error:



      / # ./run.sh
      /bin/sh: ./run.sh: not found
      / # cat run.sh
      #!/usr/bin/bash

      echo "Hi"


      workaround (1): after the apk add bash, do an:



      RUN ln -s /bin/bash /usr/bin


      in your Dockerfile. This will create a symlink for bash, allowing the program to run:



      / # ln -s /bin/bash /usr/bin
      / # ./run.sh
      Hi


      workaround(2) - if you don't want to make a symlink like this, you can always invoke bash as part of the CMD -



      CMD [ 'bash', './run.sh' ]





      share|improve this answer

























        up vote
        1
        down vote










        up vote
        1
        down vote









        The printed content of the run.sh, indicates that my original assessment was incorrect; however based on the error message, and the image of the run.sh file, I have a lead.



        Your run.sh script has an exec line of #!/bin/sh, which means that it does not need bash to operate so my previous assessment was incorrect.



        Starting on a mac, I created a run.sh script, duplicated the dockerfile (mostly), and it ran correctly, producing a valid run.



        I then converted the run.sh to use dos line endings and got the following:



        $ file run.sh
        run.sh: POSIX shell script text executable, ASCII text, with CRLF line terminators
        $ docker run --rm -it bob
        /bin/sh: ./run.sh: not found


        Which looks suspiciously like your error message.



        From this, it would lead me to believe that your run.sh file contains dos line endings. Based on the images, I'm guessing that you're on windows, which is where the problem with the run.sh script originates.



        how to convert the line endings (some examples):




        • dos2unix run.sh

        • perl -pi -e 's/rn/n/g' run.sh


        Previous Answer



        The most likely reason for this issue is that the shebang line in the run.sh contains: #!/usr/bin/bash, or something of that ilk - i.e. it doesn't reference the valid path to the binary that will run the shell script.



        On alpine, bash is installed into /bin, so if you try to run the script you will see the error:



        / # ./run.sh
        /bin/sh: ./run.sh: not found
        / # cat run.sh
        #!/usr/bin/bash

        echo "Hi"


        workaround (1): after the apk add bash, do an:



        RUN ln -s /bin/bash /usr/bin


        in your Dockerfile. This will create a symlink for bash, allowing the program to run:



        / # ln -s /bin/bash /usr/bin
        / # ./run.sh
        Hi


        workaround(2) - if you don't want to make a symlink like this, you can always invoke bash as part of the CMD -



        CMD [ 'bash', './run.sh' ]





        share|improve this answer














        The printed content of the run.sh, indicates that my original assessment was incorrect; however based on the error message, and the image of the run.sh file, I have a lead.



        Your run.sh script has an exec line of #!/bin/sh, which means that it does not need bash to operate so my previous assessment was incorrect.



        Starting on a mac, I created a run.sh script, duplicated the dockerfile (mostly), and it ran correctly, producing a valid run.



        I then converted the run.sh to use dos line endings and got the following:



        $ file run.sh
        run.sh: POSIX shell script text executable, ASCII text, with CRLF line terminators
        $ docker run --rm -it bob
        /bin/sh: ./run.sh: not found


        Which looks suspiciously like your error message.



        From this, it would lead me to believe that your run.sh file contains dos line endings. Based on the images, I'm guessing that you're on windows, which is where the problem with the run.sh script originates.



        how to convert the line endings (some examples):




        • dos2unix run.sh

        • perl -pi -e 's/rn/n/g' run.sh


        Previous Answer



        The most likely reason for this issue is that the shebang line in the run.sh contains: #!/usr/bin/bash, or something of that ilk - i.e. it doesn't reference the valid path to the binary that will run the shell script.



        On alpine, bash is installed into /bin, so if you try to run the script you will see the error:



        / # ./run.sh
        /bin/sh: ./run.sh: not found
        / # cat run.sh
        #!/usr/bin/bash

        echo "Hi"


        workaround (1): after the apk add bash, do an:



        RUN ln -s /bin/bash /usr/bin


        in your Dockerfile. This will create a symlink for bash, allowing the program to run:



        / # ln -s /bin/bash /usr/bin
        / # ./run.sh
        Hi


        workaround(2) - if you don't want to make a symlink like this, you can always invoke bash as part of the CMD -



        CMD [ 'bash', './run.sh' ]






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 21 at 13:17

























        answered Nov 20 at 15:19









        Petesh

        68.3k37296




        68.3k37296






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395463%2fdocker-image-openjdk8-jdk-alpine-fails-to-execute-a-simple-command%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'