How do i have a JAVA_HOME set using a Dockerfile and python?












0














I am trying to set up a Dockerfile for my project and am unsure how to set a JAVA_HOME within the container.



FROM python:3.6
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# Define environment variable
ENV NAME Netflow
# Run netflow.py
CMD ["python", "netflow.py"]


In the requirements.txt I have...



numpy
pandas
kafka
pyspark
log


My netflow.py file is...



import pandas, math, re, log
from pyspark import SparkConf, SparkContext
from pyspark.sql import SQLContext


conf = SparkConf().setAppName("building a warehouse")
sc = SparkContext(conf=conf)
df=pandas.read_csv(r'TestDataSet.csv')


The output in the terminal after trying to run it is....



JAVA_HOME is not set
Traceback (most recent call last):
File "netflow.py", line 7, in <module>
sc = SparkContext(conf=conf)
File "/usr/local/lib/python3.6/site-packages/pyspark/context.py", line 115, in __init__
SparkContext._ensure_initialized(self, gateway=gateway, conf=conf)
File "/usr/local/lib/python3.6/site-packages/pyspark/context.py", line 298, in _ensure_initialized
SparkContext._gateway = gateway or launch_gateway(conf)
File "/usr/local/lib/python3.6/site-packages/pyspark/java_gateway.py", line 94, in launch_gateway
raise Exception("Java gateway process exited before sending its port number")


I have been looking for a solution but none have worked so far.



I have tried



ENV JAVA_HOME /Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home


and I have tried using a separate command



docker run -e "JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home" project env


I am still getting the same error










share|improve this question





























    0














    I am trying to set up a Dockerfile for my project and am unsure how to set a JAVA_HOME within the container.



    FROM python:3.6
    # Set the working directory to /app
    WORKDIR /app
    # Copy the current directory contents into the container at /app
    COPY . /app
    # Install any needed packages specified in requirements.txt
    RUN pip install --trusted-host pypi.python.org -r requirements.txt
    # Define environment variable
    ENV NAME Netflow
    # Run netflow.py
    CMD ["python", "netflow.py"]


    In the requirements.txt I have...



    numpy
    pandas
    kafka
    pyspark
    log


    My netflow.py file is...



    import pandas, math, re, log
    from pyspark import SparkConf, SparkContext
    from pyspark.sql import SQLContext


    conf = SparkConf().setAppName("building a warehouse")
    sc = SparkContext(conf=conf)
    df=pandas.read_csv(r'TestDataSet.csv')


    The output in the terminal after trying to run it is....



    JAVA_HOME is not set
    Traceback (most recent call last):
    File "netflow.py", line 7, in <module>
    sc = SparkContext(conf=conf)
    File "/usr/local/lib/python3.6/site-packages/pyspark/context.py", line 115, in __init__
    SparkContext._ensure_initialized(self, gateway=gateway, conf=conf)
    File "/usr/local/lib/python3.6/site-packages/pyspark/context.py", line 298, in _ensure_initialized
    SparkContext._gateway = gateway or launch_gateway(conf)
    File "/usr/local/lib/python3.6/site-packages/pyspark/java_gateway.py", line 94, in launch_gateway
    raise Exception("Java gateway process exited before sending its port number")


    I have been looking for a solution but none have worked so far.



    I have tried



    ENV JAVA_HOME /Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home


    and I have tried using a separate command



    docker run -e "JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home" project env


    I am still getting the same error










    share|improve this question



























      0












      0








      0







      I am trying to set up a Dockerfile for my project and am unsure how to set a JAVA_HOME within the container.



      FROM python:3.6
      # Set the working directory to /app
      WORKDIR /app
      # Copy the current directory contents into the container at /app
      COPY . /app
      # Install any needed packages specified in requirements.txt
      RUN pip install --trusted-host pypi.python.org -r requirements.txt
      # Define environment variable
      ENV NAME Netflow
      # Run netflow.py
      CMD ["python", "netflow.py"]


      In the requirements.txt I have...



      numpy
      pandas
      kafka
      pyspark
      log


      My netflow.py file is...



      import pandas, math, re, log
      from pyspark import SparkConf, SparkContext
      from pyspark.sql import SQLContext


      conf = SparkConf().setAppName("building a warehouse")
      sc = SparkContext(conf=conf)
      df=pandas.read_csv(r'TestDataSet.csv')


      The output in the terminal after trying to run it is....



      JAVA_HOME is not set
      Traceback (most recent call last):
      File "netflow.py", line 7, in <module>
      sc = SparkContext(conf=conf)
      File "/usr/local/lib/python3.6/site-packages/pyspark/context.py", line 115, in __init__
      SparkContext._ensure_initialized(self, gateway=gateway, conf=conf)
      File "/usr/local/lib/python3.6/site-packages/pyspark/context.py", line 298, in _ensure_initialized
      SparkContext._gateway = gateway or launch_gateway(conf)
      File "/usr/local/lib/python3.6/site-packages/pyspark/java_gateway.py", line 94, in launch_gateway
      raise Exception("Java gateway process exited before sending its port number")


      I have been looking for a solution but none have worked so far.



      I have tried



      ENV JAVA_HOME /Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home


      and I have tried using a separate command



      docker run -e "JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home" project env


      I am still getting the same error










      share|improve this question















      I am trying to set up a Dockerfile for my project and am unsure how to set a JAVA_HOME within the container.



      FROM python:3.6
      # Set the working directory to /app
      WORKDIR /app
      # Copy the current directory contents into the container at /app
      COPY . /app
      # Install any needed packages specified in requirements.txt
      RUN pip install --trusted-host pypi.python.org -r requirements.txt
      # Define environment variable
      ENV NAME Netflow
      # Run netflow.py
      CMD ["python", "netflow.py"]


      In the requirements.txt I have...



      numpy
      pandas
      kafka
      pyspark
      log


      My netflow.py file is...



      import pandas, math, re, log
      from pyspark import SparkConf, SparkContext
      from pyspark.sql import SQLContext


      conf = SparkConf().setAppName("building a warehouse")
      sc = SparkContext(conf=conf)
      df=pandas.read_csv(r'TestDataSet.csv')


      The output in the terminal after trying to run it is....



      JAVA_HOME is not set
      Traceback (most recent call last):
      File "netflow.py", line 7, in <module>
      sc = SparkContext(conf=conf)
      File "/usr/local/lib/python3.6/site-packages/pyspark/context.py", line 115, in __init__
      SparkContext._ensure_initialized(self, gateway=gateway, conf=conf)
      File "/usr/local/lib/python3.6/site-packages/pyspark/context.py", line 298, in _ensure_initialized
      SparkContext._gateway = gateway or launch_gateway(conf)
      File "/usr/local/lib/python3.6/site-packages/pyspark/java_gateway.py", line 94, in launch_gateway
      raise Exception("Java gateway process exited before sending its port number")


      I have been looking for a solution but none have worked so far.



      I have tried



      ENV JAVA_HOME /Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home


      and I have tried using a separate command



      docker run -e "JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home" project env


      I am still getting the same error







      java python docker pyspark






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 5:15

























      asked Nov 21 '18 at 3:49









      Haytes

      519




      519
























          2 Answers
          2






          active

          oldest

          votes


















          2














          You need to actually install Java inside your container, but I would suggest rather finding a Pyspark docker image, or adding Python to the Openjdk images so that you don't need to mess with too many environment variables



          More specifically, JAVA_HOME=/Library/Java/JavaVirtualMachines is a only available as a path to your Mac, and shouldn't be expected to work inside a Linux container



          However, it's not clear why you need Pyspark when numpy is the only thing actually reading your data






          share|improve this answer





























            1














            To set environment variables, you can declare them in your dockerfile like so:



            ENV JAVA_HOME="foo"


            or



            ENV JAVA_HOME foo


            In fact, you already set an environment variable in the example you posted.



            See documentation for more details.






            share|improve this answer





















            • Is it possible to do something like ENV JAVA_HOME = $JAVA_HOME
              – Haytes
              Nov 21 '18 at 4:18












            • well, it wouldn't do anything really. $JAVA_HOME is the syntax to get the value of "JAVA_HOME". So effectively it would be assigning value of the variable back to itself.
              – richflow
              Nov 21 '18 at 4:55










            • I updated the question to show what I hav tried since your answer
              – Haytes
              Nov 21 '18 at 5:12








            • 1




              @Haytes Check out cricket_007's answer below. It's a better general answer to your problem and has an answer to your follow up question.
              – richflow
              Nov 21 '18 at 6:11











            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%2f53405006%2fhow-do-i-have-a-java-home-set-using-a-dockerfile-and-python%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









            2














            You need to actually install Java inside your container, but I would suggest rather finding a Pyspark docker image, or adding Python to the Openjdk images so that you don't need to mess with too many environment variables



            More specifically, JAVA_HOME=/Library/Java/JavaVirtualMachines is a only available as a path to your Mac, and shouldn't be expected to work inside a Linux container



            However, it's not clear why you need Pyspark when numpy is the only thing actually reading your data






            share|improve this answer


























              2














              You need to actually install Java inside your container, but I would suggest rather finding a Pyspark docker image, or adding Python to the Openjdk images so that you don't need to mess with too many environment variables



              More specifically, JAVA_HOME=/Library/Java/JavaVirtualMachines is a only available as a path to your Mac, and shouldn't be expected to work inside a Linux container



              However, it's not clear why you need Pyspark when numpy is the only thing actually reading your data






              share|improve this answer
























                2












                2








                2






                You need to actually install Java inside your container, but I would suggest rather finding a Pyspark docker image, or adding Python to the Openjdk images so that you don't need to mess with too many environment variables



                More specifically, JAVA_HOME=/Library/Java/JavaVirtualMachines is a only available as a path to your Mac, and shouldn't be expected to work inside a Linux container



                However, it's not clear why you need Pyspark when numpy is the only thing actually reading your data






                share|improve this answer












                You need to actually install Java inside your container, but I would suggest rather finding a Pyspark docker image, or adding Python to the Openjdk images so that you don't need to mess with too many environment variables



                More specifically, JAVA_HOME=/Library/Java/JavaVirtualMachines is a only available as a path to your Mac, and shouldn't be expected to work inside a Linux container



                However, it's not clear why you need Pyspark when numpy is the only thing actually reading your data







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 21 '18 at 5:17









                cricket_007

                79.5k1142109




                79.5k1142109

























                    1














                    To set environment variables, you can declare them in your dockerfile like so:



                    ENV JAVA_HOME="foo"


                    or



                    ENV JAVA_HOME foo


                    In fact, you already set an environment variable in the example you posted.



                    See documentation for more details.






                    share|improve this answer





















                    • Is it possible to do something like ENV JAVA_HOME = $JAVA_HOME
                      – Haytes
                      Nov 21 '18 at 4:18












                    • well, it wouldn't do anything really. $JAVA_HOME is the syntax to get the value of "JAVA_HOME". So effectively it would be assigning value of the variable back to itself.
                      – richflow
                      Nov 21 '18 at 4:55










                    • I updated the question to show what I hav tried since your answer
                      – Haytes
                      Nov 21 '18 at 5:12








                    • 1




                      @Haytes Check out cricket_007's answer below. It's a better general answer to your problem and has an answer to your follow up question.
                      – richflow
                      Nov 21 '18 at 6:11
















                    1














                    To set environment variables, you can declare them in your dockerfile like so:



                    ENV JAVA_HOME="foo"


                    or



                    ENV JAVA_HOME foo


                    In fact, you already set an environment variable in the example you posted.



                    See documentation for more details.






                    share|improve this answer





















                    • Is it possible to do something like ENV JAVA_HOME = $JAVA_HOME
                      – Haytes
                      Nov 21 '18 at 4:18












                    • well, it wouldn't do anything really. $JAVA_HOME is the syntax to get the value of "JAVA_HOME". So effectively it would be assigning value of the variable back to itself.
                      – richflow
                      Nov 21 '18 at 4:55










                    • I updated the question to show what I hav tried since your answer
                      – Haytes
                      Nov 21 '18 at 5:12








                    • 1




                      @Haytes Check out cricket_007's answer below. It's a better general answer to your problem and has an answer to your follow up question.
                      – richflow
                      Nov 21 '18 at 6:11














                    1












                    1








                    1






                    To set environment variables, you can declare them in your dockerfile like so:



                    ENV JAVA_HOME="foo"


                    or



                    ENV JAVA_HOME foo


                    In fact, you already set an environment variable in the example you posted.



                    See documentation for more details.






                    share|improve this answer












                    To set environment variables, you can declare them in your dockerfile like so:



                    ENV JAVA_HOME="foo"


                    or



                    ENV JAVA_HOME foo


                    In fact, you already set an environment variable in the example you posted.



                    See documentation for more details.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 21 '18 at 3:56









                    richflow

                    866210




                    866210












                    • Is it possible to do something like ENV JAVA_HOME = $JAVA_HOME
                      – Haytes
                      Nov 21 '18 at 4:18












                    • well, it wouldn't do anything really. $JAVA_HOME is the syntax to get the value of "JAVA_HOME". So effectively it would be assigning value of the variable back to itself.
                      – richflow
                      Nov 21 '18 at 4:55










                    • I updated the question to show what I hav tried since your answer
                      – Haytes
                      Nov 21 '18 at 5:12








                    • 1




                      @Haytes Check out cricket_007's answer below. It's a better general answer to your problem and has an answer to your follow up question.
                      – richflow
                      Nov 21 '18 at 6:11


















                    • Is it possible to do something like ENV JAVA_HOME = $JAVA_HOME
                      – Haytes
                      Nov 21 '18 at 4:18












                    • well, it wouldn't do anything really. $JAVA_HOME is the syntax to get the value of "JAVA_HOME". So effectively it would be assigning value of the variable back to itself.
                      – richflow
                      Nov 21 '18 at 4:55










                    • I updated the question to show what I hav tried since your answer
                      – Haytes
                      Nov 21 '18 at 5:12








                    • 1




                      @Haytes Check out cricket_007's answer below. It's a better general answer to your problem and has an answer to your follow up question.
                      – richflow
                      Nov 21 '18 at 6:11
















                    Is it possible to do something like ENV JAVA_HOME = $JAVA_HOME
                    – Haytes
                    Nov 21 '18 at 4:18






                    Is it possible to do something like ENV JAVA_HOME = $JAVA_HOME
                    – Haytes
                    Nov 21 '18 at 4:18














                    well, it wouldn't do anything really. $JAVA_HOME is the syntax to get the value of "JAVA_HOME". So effectively it would be assigning value of the variable back to itself.
                    – richflow
                    Nov 21 '18 at 4:55




                    well, it wouldn't do anything really. $JAVA_HOME is the syntax to get the value of "JAVA_HOME". So effectively it would be assigning value of the variable back to itself.
                    – richflow
                    Nov 21 '18 at 4:55












                    I updated the question to show what I hav tried since your answer
                    – Haytes
                    Nov 21 '18 at 5:12






                    I updated the question to show what I hav tried since your answer
                    – Haytes
                    Nov 21 '18 at 5:12






                    1




                    1




                    @Haytes Check out cricket_007's answer below. It's a better general answer to your problem and has an answer to your follow up question.
                    – richflow
                    Nov 21 '18 at 6:11




                    @Haytes Check out cricket_007's answer below. It's a better general answer to your problem and has an answer to your follow up question.
                    – richflow
                    Nov 21 '18 at 6:11


















                    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%2f53405006%2fhow-do-i-have-a-java-home-set-using-a-dockerfile-and-python%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

                    Costa Masnaga

                    Fotorealismo

                    Sidney Franklin