Docker Run fails for a Python Project











up vote
0
down vote

favorite












I have the following project structure for one of my Python project:



raspi-motion-detection
|-- project
|-- core
|-- motion_detector.py
|-- conf
|-- conf.json


I then have the following Dockerfile:



FROM     jfloff/alpine-python
RUN mkdir -p /raspi_motion_detection/project
WORKDIR /raspi_motion_detection/project
COPY ./ $WORKDIR/
COPY ./requirements.txt $WORKDIR/
ADD . $WORKDIR
CMD ["python", "/core/motion_detector.py --conf conf/conf.json"]


Building the image works fine, but when I tried to run it, I get the following error:



Joes-MacBook-Pro-78:project joe$ docker run joesan/dummy
python: can't open file '/raspi_motion_detection/project/core/motion_detector.py --conf /raspi_motion_detection/project/conf/conf.json': [Errno 2] No such file or directory
Joes-MacBook-Pro-78:project joe$


Any ideas as to what is happening? I did in fact ADD the WORKDIR to the Docker runtime, but still it would not find the necessary Python file.










share|improve this question


























    up vote
    0
    down vote

    favorite












    I have the following project structure for one of my Python project:



    raspi-motion-detection
    |-- project
    |-- core
    |-- motion_detector.py
    |-- conf
    |-- conf.json


    I then have the following Dockerfile:



    FROM     jfloff/alpine-python
    RUN mkdir -p /raspi_motion_detection/project
    WORKDIR /raspi_motion_detection/project
    COPY ./ $WORKDIR/
    COPY ./requirements.txt $WORKDIR/
    ADD . $WORKDIR
    CMD ["python", "/core/motion_detector.py --conf conf/conf.json"]


    Building the image works fine, but when I tried to run it, I get the following error:



    Joes-MacBook-Pro-78:project joe$ docker run joesan/dummy
    python: can't open file '/raspi_motion_detection/project/core/motion_detector.py --conf /raspi_motion_detection/project/conf/conf.json': [Errno 2] No such file or directory
    Joes-MacBook-Pro-78:project joe$


    Any ideas as to what is happening? I did in fact ADD the WORKDIR to the Docker runtime, but still it would not find the necessary Python file.










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have the following project structure for one of my Python project:



      raspi-motion-detection
      |-- project
      |-- core
      |-- motion_detector.py
      |-- conf
      |-- conf.json


      I then have the following Dockerfile:



      FROM     jfloff/alpine-python
      RUN mkdir -p /raspi_motion_detection/project
      WORKDIR /raspi_motion_detection/project
      COPY ./ $WORKDIR/
      COPY ./requirements.txt $WORKDIR/
      ADD . $WORKDIR
      CMD ["python", "/core/motion_detector.py --conf conf/conf.json"]


      Building the image works fine, but when I tried to run it, I get the following error:



      Joes-MacBook-Pro-78:project joe$ docker run joesan/dummy
      python: can't open file '/raspi_motion_detection/project/core/motion_detector.py --conf /raspi_motion_detection/project/conf/conf.json': [Errno 2] No such file or directory
      Joes-MacBook-Pro-78:project joe$


      Any ideas as to what is happening? I did in fact ADD the WORKDIR to the Docker runtime, but still it would not find the necessary Python file.










      share|improve this question













      I have the following project structure for one of my Python project:



      raspi-motion-detection
      |-- project
      |-- core
      |-- motion_detector.py
      |-- conf
      |-- conf.json


      I then have the following Dockerfile:



      FROM     jfloff/alpine-python
      RUN mkdir -p /raspi_motion_detection/project
      WORKDIR /raspi_motion_detection/project
      COPY ./ $WORKDIR/
      COPY ./requirements.txt $WORKDIR/
      ADD . $WORKDIR
      CMD ["python", "/core/motion_detector.py --conf conf/conf.json"]


      Building the image works fine, but when I tried to run it, I get the following error:



      Joes-MacBook-Pro-78:project joe$ docker run joesan/dummy
      python: can't open file '/raspi_motion_detection/project/core/motion_detector.py --conf /raspi_motion_detection/project/conf/conf.json': [Errno 2] No such file or directory
      Joes-MacBook-Pro-78:project joe$


      Any ideas as to what is happening? I did in fact ADD the WORKDIR to the Docker runtime, but still it would not find the necessary Python file.







      python docker






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 11 at 12:14









      sparkr

      4,9081240107




      4,9081240107
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          In the last line of your Dockerfile:



          CMD ["python", "/core/motion_detector.py --conf conf/conf.json"]


          When the container starts up it is trying to launch python and pass it a single argument, which it interprets as the filename of a script to run. That argument, which is interpreted in its entirety as a script name, is /core/... conf/conf.json. Since you don't have a single file with that name, spaces and options and all, Python fails.



          If you're using the JSON-ish syntax you need to break each separate argument into its own "word":



          CMD ["python", "core/motion_detector.py", "--conf", "conf/conf.json"]


          (Note that the WORKDIR directive globally changes the working directory for all subsequent commands, the default directory for COPY and ADD directives, and any ENTRYPOINT and/or CMD that eventually gets run. There's no $WORKDIR variable you can reference, and I suspect variable expansion is actually causing files end up in the container root directory when you don't expect. Try just COPY ./ ./ to add content to the image.)






          share|improve this answer





















          • Cool! That worked! I understood what my mistake is!
            – sparkr
            Nov 11 at 12:38


















          up vote
          0
          down vote













          Well you use fully qualified paths like they are relative.



          Assuming that your Dockerfile is situated in the raspi-motion-detection folder in your project structure...



          CMD      ["python", "/core/motion_detector.py", "--conf", "conf/conf.json"]


          The /core... part (note I broke all the command parts into separate items) will actually point to a location relative to the root folder as it starts with a '/' and it should actially look from here:



          /raspi_motion_detection/project/project/core/motion_detector.py


          the same goes for the conf/conf.json that one will actually point to something relative to the WORKDIR. you might want to be more specific here too :-)



          you can check your config by running something like:



          docker run -it --rm your_image /bin/bash


          and then look around how and what you actually added where with your build.



          Your Dockerfile seems to be wrong on some points too




          • You can not reference WORKDIR with $WORKDIR

          • You copy a requirements.txt file but never run it so it will probably never do anything

          • You see to copy the whole structure and dat will include the Dockerfile which is unnecessary


          Hope it helps






          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%2f53248652%2fdocker-run-fails-for-a-python-project%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote



            accepted










            In the last line of your Dockerfile:



            CMD ["python", "/core/motion_detector.py --conf conf/conf.json"]


            When the container starts up it is trying to launch python and pass it a single argument, which it interprets as the filename of a script to run. That argument, which is interpreted in its entirety as a script name, is /core/... conf/conf.json. Since you don't have a single file with that name, spaces and options and all, Python fails.



            If you're using the JSON-ish syntax you need to break each separate argument into its own "word":



            CMD ["python", "core/motion_detector.py", "--conf", "conf/conf.json"]


            (Note that the WORKDIR directive globally changes the working directory for all subsequent commands, the default directory for COPY and ADD directives, and any ENTRYPOINT and/or CMD that eventually gets run. There's no $WORKDIR variable you can reference, and I suspect variable expansion is actually causing files end up in the container root directory when you don't expect. Try just COPY ./ ./ to add content to the image.)






            share|improve this answer





















            • Cool! That worked! I understood what my mistake is!
              – sparkr
              Nov 11 at 12:38















            up vote
            2
            down vote



            accepted










            In the last line of your Dockerfile:



            CMD ["python", "/core/motion_detector.py --conf conf/conf.json"]


            When the container starts up it is trying to launch python and pass it a single argument, which it interprets as the filename of a script to run. That argument, which is interpreted in its entirety as a script name, is /core/... conf/conf.json. Since you don't have a single file with that name, spaces and options and all, Python fails.



            If you're using the JSON-ish syntax you need to break each separate argument into its own "word":



            CMD ["python", "core/motion_detector.py", "--conf", "conf/conf.json"]


            (Note that the WORKDIR directive globally changes the working directory for all subsequent commands, the default directory for COPY and ADD directives, and any ENTRYPOINT and/or CMD that eventually gets run. There's no $WORKDIR variable you can reference, and I suspect variable expansion is actually causing files end up in the container root directory when you don't expect. Try just COPY ./ ./ to add content to the image.)






            share|improve this answer





















            • Cool! That worked! I understood what my mistake is!
              – sparkr
              Nov 11 at 12:38













            up vote
            2
            down vote



            accepted







            up vote
            2
            down vote



            accepted






            In the last line of your Dockerfile:



            CMD ["python", "/core/motion_detector.py --conf conf/conf.json"]


            When the container starts up it is trying to launch python and pass it a single argument, which it interprets as the filename of a script to run. That argument, which is interpreted in its entirety as a script name, is /core/... conf/conf.json. Since you don't have a single file with that name, spaces and options and all, Python fails.



            If you're using the JSON-ish syntax you need to break each separate argument into its own "word":



            CMD ["python", "core/motion_detector.py", "--conf", "conf/conf.json"]


            (Note that the WORKDIR directive globally changes the working directory for all subsequent commands, the default directory for COPY and ADD directives, and any ENTRYPOINT and/or CMD that eventually gets run. There's no $WORKDIR variable you can reference, and I suspect variable expansion is actually causing files end up in the container root directory when you don't expect. Try just COPY ./ ./ to add content to the image.)






            share|improve this answer












            In the last line of your Dockerfile:



            CMD ["python", "/core/motion_detector.py --conf conf/conf.json"]


            When the container starts up it is trying to launch python and pass it a single argument, which it interprets as the filename of a script to run. That argument, which is interpreted in its entirety as a script name, is /core/... conf/conf.json. Since you don't have a single file with that name, spaces and options and all, Python fails.



            If you're using the JSON-ish syntax you need to break each separate argument into its own "word":



            CMD ["python", "core/motion_detector.py", "--conf", "conf/conf.json"]


            (Note that the WORKDIR directive globally changes the working directory for all subsequent commands, the default directory for COPY and ADD directives, and any ENTRYPOINT and/or CMD that eventually gets run. There's no $WORKDIR variable you can reference, and I suspect variable expansion is actually causing files end up in the container root directory when you don't expect. Try just COPY ./ ./ to add content to the image.)







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 11 at 12:31









            David Maze

            8,6082821




            8,6082821












            • Cool! That worked! I understood what my mistake is!
              – sparkr
              Nov 11 at 12:38


















            • Cool! That worked! I understood what my mistake is!
              – sparkr
              Nov 11 at 12:38
















            Cool! That worked! I understood what my mistake is!
            – sparkr
            Nov 11 at 12:38




            Cool! That worked! I understood what my mistake is!
            – sparkr
            Nov 11 at 12:38












            up vote
            0
            down vote













            Well you use fully qualified paths like they are relative.



            Assuming that your Dockerfile is situated in the raspi-motion-detection folder in your project structure...



            CMD      ["python", "/core/motion_detector.py", "--conf", "conf/conf.json"]


            The /core... part (note I broke all the command parts into separate items) will actually point to a location relative to the root folder as it starts with a '/' and it should actially look from here:



            /raspi_motion_detection/project/project/core/motion_detector.py


            the same goes for the conf/conf.json that one will actually point to something relative to the WORKDIR. you might want to be more specific here too :-)



            you can check your config by running something like:



            docker run -it --rm your_image /bin/bash


            and then look around how and what you actually added where with your build.



            Your Dockerfile seems to be wrong on some points too




            • You can not reference WORKDIR with $WORKDIR

            • You copy a requirements.txt file but never run it so it will probably never do anything

            • You see to copy the whole structure and dat will include the Dockerfile which is unnecessary


            Hope it helps






            share|improve this answer



























              up vote
              0
              down vote













              Well you use fully qualified paths like they are relative.



              Assuming that your Dockerfile is situated in the raspi-motion-detection folder in your project structure...



              CMD      ["python", "/core/motion_detector.py", "--conf", "conf/conf.json"]


              The /core... part (note I broke all the command parts into separate items) will actually point to a location relative to the root folder as it starts with a '/' and it should actially look from here:



              /raspi_motion_detection/project/project/core/motion_detector.py


              the same goes for the conf/conf.json that one will actually point to something relative to the WORKDIR. you might want to be more specific here too :-)



              you can check your config by running something like:



              docker run -it --rm your_image /bin/bash


              and then look around how and what you actually added where with your build.



              Your Dockerfile seems to be wrong on some points too




              • You can not reference WORKDIR with $WORKDIR

              • You copy a requirements.txt file but never run it so it will probably never do anything

              • You see to copy the whole structure and dat will include the Dockerfile which is unnecessary


              Hope it helps






              share|improve this answer

























                up vote
                0
                down vote










                up vote
                0
                down vote









                Well you use fully qualified paths like they are relative.



                Assuming that your Dockerfile is situated in the raspi-motion-detection folder in your project structure...



                CMD      ["python", "/core/motion_detector.py", "--conf", "conf/conf.json"]


                The /core... part (note I broke all the command parts into separate items) will actually point to a location relative to the root folder as it starts with a '/' and it should actially look from here:



                /raspi_motion_detection/project/project/core/motion_detector.py


                the same goes for the conf/conf.json that one will actually point to something relative to the WORKDIR. you might want to be more specific here too :-)



                you can check your config by running something like:



                docker run -it --rm your_image /bin/bash


                and then look around how and what you actually added where with your build.



                Your Dockerfile seems to be wrong on some points too




                • You can not reference WORKDIR with $WORKDIR

                • You copy a requirements.txt file but never run it so it will probably never do anything

                • You see to copy the whole structure and dat will include the Dockerfile which is unnecessary


                Hope it helps






                share|improve this answer














                Well you use fully qualified paths like they are relative.



                Assuming that your Dockerfile is situated in the raspi-motion-detection folder in your project structure...



                CMD      ["python", "/core/motion_detector.py", "--conf", "conf/conf.json"]


                The /core... part (note I broke all the command parts into separate items) will actually point to a location relative to the root folder as it starts with a '/' and it should actially look from here:



                /raspi_motion_detection/project/project/core/motion_detector.py


                the same goes for the conf/conf.json that one will actually point to something relative to the WORKDIR. you might want to be more specific here too :-)



                you can check your config by running something like:



                docker run -it --rm your_image /bin/bash


                and then look around how and what you actually added where with your build.



                Your Dockerfile seems to be wrong on some points too




                • You can not reference WORKDIR with $WORKDIR

                • You copy a requirements.txt file but never run it so it will probably never do anything

                • You see to copy the whole structure and dat will include the Dockerfile which is unnecessary


                Hope it helps







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 11 at 12:38

























                answered Nov 11 at 12:27









                Ivonet

                1,153518




                1,153518






























                    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%2f53248652%2fdocker-run-fails-for-a-python-project%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

                    Full-time equivalent

                    Bicuculline

                    さくらももこ