Entorno para desarrollo con PySpark usando docker (imagen de bitcami).
- Docker
- Docker compose
Para poner a funcionar el entorno simplemente es necesario iniciarlo con:
docker-compose up -dUna vez hemos iniciado los contenedores es necesario esperar unos segundos ya que tarda unos instantes en instalar e iniciar el servidor de jupyter.
Por defecto el servidor estará funcionando en el localhost pero en caso de querer usar la ip podemos obtenerla con el siguiente comando:
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' docker-spark-master-1Para apagarlo:
docker-compose downEl entorno por defecto consta de 2 workers y 1 master.
Desde el archivo docker-compose el master ejecuta el script docker-start, este lo que hace es:
- Inicia spark
- Instala las bibliotecas de
pysparkynotebook. - Inicia el servidor de Jupyter.
Importante
El servidor de Jupyter se inicia de manera que no requiere de contraseña y admite conexiones desde cualquier lado, no es recomendable mantener esta configuración en la mayoría de los casos.
jupyter-lab --ip=0.0.0.0 --port 8888 --no-browser --notebook-dir=/proyecto --NotebookApp.allow_origin="*" --allow-root --ServerApp.password='' --ServerApp.token='' --ServerApp.password_required=FalseEn caso de usar linux es posible que el contenedor master devuelva un error, en ese caso es posible que sea necesario hacer lo siguiente antes de iniciar el entorno:
chmod +x docker-start.shEnvironment for PySpark development using docker (bitcami image).
- Docker
- Docker compose
To get the environment working, you just need to start it with:
docker-compose up -dOnce we have started the containers, we need to wait a few seconds for the jupyter server to install and start.
By default the server will run on localhost but if you want to use the ip it's possible to get it with:
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' docker-spark-master-1To shutdown:
docker-compose downBy default, the environment has 2 workers' and 1 master'.
From the docker-compose file the master runs the docker-start script, which that script does the following:
- Start Spark
- Install the
pysparkandnotebooklibraries. - Start the Jupyter server.
Important
The Jupyter server is started in a way that doesn't require a password and allows connections from anywhere, which is not recommended for most uses.
jupyter-lab --ip=0.0.0.0 --port 8888 --no-browser --notebook-dir=/proyecto --NotebookApp.allow_origin="*" --allow-root --ServerApp.password='' --ServerApp.token='' --ServerApp.password_required=FalseIn case of using linux it is possible that the master container returns an error, in that case it may be necessary to do the following before starting the environment:
chmod +x docker-start.sh
