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
java python docker pyspark
add a comment |
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
java python docker pyspark
add a comment |
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
java python docker pyspark
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
java python docker pyspark
edited Nov 21 at 5:15
asked Nov 21 at 3:49
Haytes
398
398
add a comment |
add a comment |
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
add a comment |
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.
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
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 21 at 5:17
cricket_007
77k1142106
77k1142106
add a comment |
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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