↓ Skip to main content

PySpark Notebook with PosgreSQL + PGAdmin

·174 words·1 min· loading ·
Aiman Amri
Author
Aiman Amri
Working as a Process Executive (Content Moderation) and previously worked as MS L1 Engineer (IT Support).

A simple project on how to set up PySpark with Jupyter notebook. Also, we will be using PosgreSQL server as database and PGAdmin for the interface.

Run Locally
#

Clone the project

  git clone https://github.com/aimanamri/test-docker-app.git

Go to the project directory

  cd test-docker-ap/pyspark-de

Start the server using Docker

  docker-compose -f de_env_setup.yaml up -d

This project will run on localhost:80 for PGAdmin and localhost:8888 for Jupyter notebook.

Getting token to login into Jupyter notebook
#

   docker exec -it notebook sh

Then, run following to get token for Jupyter and copy the token into http://localhost:8888.

jupyter server list

Codes (de_env_setup.yaml)
#


services:
  pg-database:
    image: postgres
    container_name: pg_db
    restart: always
    ports:
    - "5432:5432"
    environment:
      POSTGRES_USER: aimang
      POSTGRES_PASSWORD: strong-password

  pgadmin:
    image: dpage/pgadmin4
    container_name: pgadmin4
    restart: always
    depends_on:
      pg-database:
        condition: service_started
    ports:
    - "80:80"
    environment:
      PGADMIN_DEFAULT_EMAIL: user-name@domain-name.com
      PGADMIN_DEFAULT_PASSWORD: strong-password
    volumes:
      - ./pgadmin-data:/var/lib/pgadmin

  pyspark-notebook:
    image: jupyter/pyspark-notebook
    container_name: notebook
    restart: always
    ports:
    - "8888:8888"
    volumes:
      - ./notebook:/home/jovyan/work

Tech Stack
#

Client:: pgadmin

Coding: Jupyter notebook with PySpark installed

Server: posgresql

Feedback
#

If you have any feedback, please open new issue here.