Jupyter Notebook (with PyPI Apache Spark)
1.4K
Need a notebook with access to a simple PySpark interpreter? Otherwise, check an alternate implementation, jupyter-spark-pseudo, which is closer to a real Spark cluster (but a bigger image).
latest%%sql cell magic support.Dockerfile linksPlace your notebooks under the notebook directory and run:
mkdir -pv notebooks && docker run --rm -d\
--name jupyter-pyspark\
--hostname localhost\
--env JUPYTER_PORT=8889\
--env DRIVER_MEMORY=2g\
--volume $PWD/notebooks:/home/user/notebooks\
--publish 8889:8889\
loum/jupyter-pyspark:latest
To get the URL of your local server:
docker exec -ti jupyter-pyspark bash -c "jupyter notebook list"
docker stop jupyter-pyspark
With an active Jupyter Notebook server a PySpark instance should be running behind the scenes. To validate, dump the SparkContext help in a Jupyter Notebook cell:
help(sc)
Spark context available as sc.
SparkSession available as spark.
Taken from Spark examples:
import sys
from random import random
from operator import add
partitions = 2
n = 100000 * partitions
def f(_):
x = random() * 2 - 1
y = random() * 2 - 1
return 1 if x ** 2 + y ** 2 <= 1 else 0
count = sc.parallelize(range(1, n + 1), partitions).map(f).reduce(add)
print("Pi is roughly %f" % (4.0 * count / n))
[Stage 0:> (0 + 2) / 2]
Pi is roughly 3.143960
Content type
Image
Digest
sha256:d4dcd3cc9…
Size
726.4 MB
Last updated
over 1 year ago
docker pull loum/jupyter-pyspark:7.3.2-3.5.4