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











up vote
0
down vote

favorite












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




























    up vote
    0
    down vote

    favorite












    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


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      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 at 5:15

























      asked Nov 21 at 3:49









      Haytes

      398




      398
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          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




























            up vote
            1
            down vote













            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 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 at 4:55










            • I updated the question to show what I hav tried since your answer
              – Haytes
              Nov 21 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 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',
            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








            up vote
            2
            down vote



            accepted










            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

























              up vote
              2
              down vote



              accepted










              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























                up vote
                2
                down vote



                accepted







                up vote
                2
                down vote



                accepted






                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 at 5:17









                cricket_007

                77k1142106




                77k1142106
























                    up vote
                    1
                    down vote













                    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 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 at 4:55










                    • I updated the question to show what I hav tried since your answer
                      – Haytes
                      Nov 21 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 at 6:11















                    up vote
                    1
                    down vote













                    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 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 at 4:55










                    • I updated the question to show what I hav tried since your answer
                      – Haytes
                      Nov 21 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 at 6:11













                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    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 at 3:56









                    richflow

                    571110




                    571110












                    • Is it possible to do something like ENV JAVA_HOME = $JAVA_HOME
                      – Haytes
                      Nov 21 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 at 4:55










                    • I updated the question to show what I hav tried since your answer
                      – Haytes
                      Nov 21 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 at 6:11


















                    • Is it possible to do something like ENV JAVA_HOME = $JAVA_HOME
                      – Haytes
                      Nov 21 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 at 4:55










                    • I updated the question to show what I hav tried since your answer
                      – Haytes
                      Nov 21 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 at 6:11
















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






                    Is it possible to do something like ENV JAVA_HOME = $JAVA_HOME
                    – Haytes
                    Nov 21 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 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 at 4:55












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






                    I updated the question to show what I hav tried since your answer
                    – Haytes
                    Nov 21 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 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 at 6:11


















                     

                    draft saved


                    draft discarded



















































                     


                    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

                    Berounka

                    Sphinx de Gizeh

                    Different font size/position of beamer's navigation symbols template's content depending on regular/plain...