Docker - Add Python and Dependencies to Apache












1















I have a python script that I am trying to create a docker container for. I am new to docker so please excuse if this is real simple!



If I am setting up my existing python script on a new system I always run the following to install dependencies....



pip install numpy opencv-python dlib imutils


I have a basic Dockerfile that loads PHP with apache like this...



FROM php:7.0-apache
COPY src/ /var/www/html
EXPOSE 80


Is there a way I can add Python into the stack and install those dependencies? Or have I got Docker totally wrong?










share|improve this question



























    1















    I have a python script that I am trying to create a docker container for. I am new to docker so please excuse if this is real simple!



    If I am setting up my existing python script on a new system I always run the following to install dependencies....



    pip install numpy opencv-python dlib imutils


    I have a basic Dockerfile that loads PHP with apache like this...



    FROM php:7.0-apache
    COPY src/ /var/www/html
    EXPOSE 80


    Is there a way I can add Python into the stack and install those dependencies? Or have I got Docker totally wrong?










    share|improve this question

























      1












      1








      1


      1






      I have a python script that I am trying to create a docker container for. I am new to docker so please excuse if this is real simple!



      If I am setting up my existing python script on a new system I always run the following to install dependencies....



      pip install numpy opencv-python dlib imutils


      I have a basic Dockerfile that loads PHP with apache like this...



      FROM php:7.0-apache
      COPY src/ /var/www/html
      EXPOSE 80


      Is there a way I can add Python into the stack and install those dependencies? Or have I got Docker totally wrong?










      share|improve this question














      I have a python script that I am trying to create a docker container for. I am new to docker so please excuse if this is real simple!



      If I am setting up my existing python script on a new system I always run the following to install dependencies....



      pip install numpy opencv-python dlib imutils


      I have a basic Dockerfile that loads PHP with apache like this...



      FROM php:7.0-apache
      COPY src/ /var/www/html
      EXPOSE 80


      Is there a way I can add Python into the stack and install those dependencies? Or have I got Docker totally wrong?







      docker dockerfile






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 19 at 13:48









      fightstarr20fightstarr20

      2,8561153111




      2,8561153111
























          1 Answer
          1






          active

          oldest

          votes


















          1














          If I understood correctly on very first point, you need to get some packages from Python then try following once(as an example, I am importing Python's 2.7 version's image here).



          FROM python2.7-slim


          Then for multiple packages installations you could create a file named requirements.txt(which will have all packages details in it) and then could run following command too in it.



          cat requirements.txt
          numpy
          opencv-python
          dlib
          imutils

          pip install -r requirements.txt







          If I am setting up my existing python script on a new system I always
          run the following to install dependencies....




          Little explanation on Concept of Docker: So concept of Docker is NOT TO INSTALL dependencies on any machines and make our codes to run on any machine without putting additional stuff to install our code's dependencies etc. Basically our Dockerize solution should be capable to handle any system. Here is what the steps would be:



          1- Create your code in Python(here taking example of it).
          2- Now place it in docker's directory.
          3- MOST important step create a file named Dockerfile in docker's directory.
          4- Now mention all sequence of commands in it, following is an example of Dockerfile`:



          FROM python2.7-slim
          DIR /app
          COPY . /app
          RUN pip install -r requirements.txt
          CMD ["python","your_python_code_file"]


          So here you could see whenever we build our image(combination of our code and Dockerfile) we need NOT TO install anything in our actual server/machine this is benefit of Docker our image SHOULD BE dependency free. Once we build our image and post it to repository same image could be used by any other person on any other machine too.






          share|improve this answer


























          • If I try like that then I get dockerfile parse error, FROM requires either one or three argumanets

            – fightstarr20
            Jan 19 at 15:13






          • 1





            This creates a just-Python image. I'm not sure about the relationship between the PHP wrapper in the original question and the Python script; if there's something like a Flask server that the PHP can call out to then this is a good start for a 2-container Docker Compose setup.

            – David Maze
            Jan 19 at 17:51











          • @DavidMaze, why I had taken python's example here because OP needs to install certain packages in it using pip.

            – RavinderSingh13
            Jan 19 at 17:53











          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',
          autoActivateHeartbeat: false,
          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%2f54267753%2fdocker-add-python-and-dependencies-to-apache%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









          1














          If I understood correctly on very first point, you need to get some packages from Python then try following once(as an example, I am importing Python's 2.7 version's image here).



          FROM python2.7-slim


          Then for multiple packages installations you could create a file named requirements.txt(which will have all packages details in it) and then could run following command too in it.



          cat requirements.txt
          numpy
          opencv-python
          dlib
          imutils

          pip install -r requirements.txt







          If I am setting up my existing python script on a new system I always
          run the following to install dependencies....




          Little explanation on Concept of Docker: So concept of Docker is NOT TO INSTALL dependencies on any machines and make our codes to run on any machine without putting additional stuff to install our code's dependencies etc. Basically our Dockerize solution should be capable to handle any system. Here is what the steps would be:



          1- Create your code in Python(here taking example of it).
          2- Now place it in docker's directory.
          3- MOST important step create a file named Dockerfile in docker's directory.
          4- Now mention all sequence of commands in it, following is an example of Dockerfile`:



          FROM python2.7-slim
          DIR /app
          COPY . /app
          RUN pip install -r requirements.txt
          CMD ["python","your_python_code_file"]


          So here you could see whenever we build our image(combination of our code and Dockerfile) we need NOT TO install anything in our actual server/machine this is benefit of Docker our image SHOULD BE dependency free. Once we build our image and post it to repository same image could be used by any other person on any other machine too.






          share|improve this answer


























          • If I try like that then I get dockerfile parse error, FROM requires either one or three argumanets

            – fightstarr20
            Jan 19 at 15:13






          • 1





            This creates a just-Python image. I'm not sure about the relationship between the PHP wrapper in the original question and the Python script; if there's something like a Flask server that the PHP can call out to then this is a good start for a 2-container Docker Compose setup.

            – David Maze
            Jan 19 at 17:51











          • @DavidMaze, why I had taken python's example here because OP needs to install certain packages in it using pip.

            – RavinderSingh13
            Jan 19 at 17:53
















          1














          If I understood correctly on very first point, you need to get some packages from Python then try following once(as an example, I am importing Python's 2.7 version's image here).



          FROM python2.7-slim


          Then for multiple packages installations you could create a file named requirements.txt(which will have all packages details in it) and then could run following command too in it.



          cat requirements.txt
          numpy
          opencv-python
          dlib
          imutils

          pip install -r requirements.txt







          If I am setting up my existing python script on a new system I always
          run the following to install dependencies....




          Little explanation on Concept of Docker: So concept of Docker is NOT TO INSTALL dependencies on any machines and make our codes to run on any machine without putting additional stuff to install our code's dependencies etc. Basically our Dockerize solution should be capable to handle any system. Here is what the steps would be:



          1- Create your code in Python(here taking example of it).
          2- Now place it in docker's directory.
          3- MOST important step create a file named Dockerfile in docker's directory.
          4- Now mention all sequence of commands in it, following is an example of Dockerfile`:



          FROM python2.7-slim
          DIR /app
          COPY . /app
          RUN pip install -r requirements.txt
          CMD ["python","your_python_code_file"]


          So here you could see whenever we build our image(combination of our code and Dockerfile) we need NOT TO install anything in our actual server/machine this is benefit of Docker our image SHOULD BE dependency free. Once we build our image and post it to repository same image could be used by any other person on any other machine too.






          share|improve this answer


























          • If I try like that then I get dockerfile parse error, FROM requires either one or three argumanets

            – fightstarr20
            Jan 19 at 15:13






          • 1





            This creates a just-Python image. I'm not sure about the relationship between the PHP wrapper in the original question and the Python script; if there's something like a Flask server that the PHP can call out to then this is a good start for a 2-container Docker Compose setup.

            – David Maze
            Jan 19 at 17:51











          • @DavidMaze, why I had taken python's example here because OP needs to install certain packages in it using pip.

            – RavinderSingh13
            Jan 19 at 17:53














          1












          1








          1







          If I understood correctly on very first point, you need to get some packages from Python then try following once(as an example, I am importing Python's 2.7 version's image here).



          FROM python2.7-slim


          Then for multiple packages installations you could create a file named requirements.txt(which will have all packages details in it) and then could run following command too in it.



          cat requirements.txt
          numpy
          opencv-python
          dlib
          imutils

          pip install -r requirements.txt







          If I am setting up my existing python script on a new system I always
          run the following to install dependencies....




          Little explanation on Concept of Docker: So concept of Docker is NOT TO INSTALL dependencies on any machines and make our codes to run on any machine without putting additional stuff to install our code's dependencies etc. Basically our Dockerize solution should be capable to handle any system. Here is what the steps would be:



          1- Create your code in Python(here taking example of it).
          2- Now place it in docker's directory.
          3- MOST important step create a file named Dockerfile in docker's directory.
          4- Now mention all sequence of commands in it, following is an example of Dockerfile`:



          FROM python2.7-slim
          DIR /app
          COPY . /app
          RUN pip install -r requirements.txt
          CMD ["python","your_python_code_file"]


          So here you could see whenever we build our image(combination of our code and Dockerfile) we need NOT TO install anything in our actual server/machine this is benefit of Docker our image SHOULD BE dependency free. Once we build our image and post it to repository same image could be used by any other person on any other machine too.






          share|improve this answer















          If I understood correctly on very first point, you need to get some packages from Python then try following once(as an example, I am importing Python's 2.7 version's image here).



          FROM python2.7-slim


          Then for multiple packages installations you could create a file named requirements.txt(which will have all packages details in it) and then could run following command too in it.



          cat requirements.txt
          numpy
          opencv-python
          dlib
          imutils

          pip install -r requirements.txt







          If I am setting up my existing python script on a new system I always
          run the following to install dependencies....




          Little explanation on Concept of Docker: So concept of Docker is NOT TO INSTALL dependencies on any machines and make our codes to run on any machine without putting additional stuff to install our code's dependencies etc. Basically our Dockerize solution should be capable to handle any system. Here is what the steps would be:



          1- Create your code in Python(here taking example of it).
          2- Now place it in docker's directory.
          3- MOST important step create a file named Dockerfile in docker's directory.
          4- Now mention all sequence of commands in it, following is an example of Dockerfile`:



          FROM python2.7-slim
          DIR /app
          COPY . /app
          RUN pip install -r requirements.txt
          CMD ["python","your_python_code_file"]


          So here you could see whenever we build our image(combination of our code and Dockerfile) we need NOT TO install anything in our actual server/machine this is benefit of Docker our image SHOULD BE dependency free. Once we build our image and post it to repository same image could be used by any other person on any other machine too.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 19 at 17:50

























          answered Jan 19 at 13:53









          RavinderSingh13RavinderSingh13

          27.3k41538




          27.3k41538













          • If I try like that then I get dockerfile parse error, FROM requires either one or three argumanets

            – fightstarr20
            Jan 19 at 15:13






          • 1





            This creates a just-Python image. I'm not sure about the relationship between the PHP wrapper in the original question and the Python script; if there's something like a Flask server that the PHP can call out to then this is a good start for a 2-container Docker Compose setup.

            – David Maze
            Jan 19 at 17:51











          • @DavidMaze, why I had taken python's example here because OP needs to install certain packages in it using pip.

            – RavinderSingh13
            Jan 19 at 17:53



















          • If I try like that then I get dockerfile parse error, FROM requires either one or three argumanets

            – fightstarr20
            Jan 19 at 15:13






          • 1





            This creates a just-Python image. I'm not sure about the relationship between the PHP wrapper in the original question and the Python script; if there's something like a Flask server that the PHP can call out to then this is a good start for a 2-container Docker Compose setup.

            – David Maze
            Jan 19 at 17:51











          • @DavidMaze, why I had taken python's example here because OP needs to install certain packages in it using pip.

            – RavinderSingh13
            Jan 19 at 17:53

















          If I try like that then I get dockerfile parse error, FROM requires either one or three argumanets

          – fightstarr20
          Jan 19 at 15:13





          If I try like that then I get dockerfile parse error, FROM requires either one or three argumanets

          – fightstarr20
          Jan 19 at 15:13




          1




          1





          This creates a just-Python image. I'm not sure about the relationship between the PHP wrapper in the original question and the Python script; if there's something like a Flask server that the PHP can call out to then this is a good start for a 2-container Docker Compose setup.

          – David Maze
          Jan 19 at 17:51





          This creates a just-Python image. I'm not sure about the relationship between the PHP wrapper in the original question and the Python script; if there's something like a Flask server that the PHP can call out to then this is a good start for a 2-container Docker Compose setup.

          – David Maze
          Jan 19 at 17:51













          @DavidMaze, why I had taken python's example here because OP needs to install certain packages in it using pip.

          – RavinderSingh13
          Jan 19 at 17:53





          @DavidMaze, why I had taken python's example here because OP needs to install certain packages in it using pip.

          – RavinderSingh13
          Jan 19 at 17:53


















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54267753%2fdocker-add-python-and-dependencies-to-apache%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

          Callistus III

          Ostreoida

          Plistias Cous