Apache Spark, PySpark can't write a file on disk

I am using the following docker compose configuration:

version: '3'

services:

  spark-master:
    build:
      network: host
      context: docker/
      dockerfile: Dockerfile_spark
    container_name: spark_master
    user: root
    ports:
      - '8090:8080'
    volumes:
#      - ./volumes/data:/opt/data
      - /mnt/c/git/sparkproject/spark/volumes/data:/opt/data
      - ./volumes/code:/opt/code
      - ./volumes/spark:/bitnami/spark
      - spark_data:/opt/data1
    environment:
      - SPARK_MODE=master
      - SPARK_RPC_AUTHENTICATION_ENABLED=no
      - SPARK_RPC_ENCRYPTION_ENABLED=no
      - SPARK_LOCAL_STORAGE_ENCRYPTION_ENABLED=no
      - SPARK_SSL_ENABLED=no
    restart: always

  spark-worker-1:
    build:
      network: host
      context: docker/
      dockerfile: Dockerfile_spark
    container_name: spark_worker_1
    user: root
    volumes:
      - /mnt/c/git/sparkproject/spark/volumes/data:/opt/data
#      - ./volumes/data:/opt/data
      - ./volumes/code:/opt/code
      - spark_data:/opt/data1
    environment:
      - SPARK_MODE=worker
      - SPARK_MASTER_URL=spark://spark-master:7077
      - SPARK_WORKER_MEMORY=4G
      - SPARK_WORKER_CORES=2
      - SPARK_RPC_AUTHENTICATION_ENABLED=no
      - SPARK_RPC_ENCRYPTION_ENABLED=no
      - SPARK_LOCAL_STORAGE_ENCRYPTION_ENABLED=no
      - SPARK_SSL_ENABLED=no
    restart: always
    depends_on:
      - spark-master

  # spark-worker-2:
  #   build:
  #     network: host
  #     context: docker/
  #     dockerfile: Dockerfile_spark
  #   container_name: spark_worker_2
  #   user: root
  #   volumes:
  #     - ./volumes/data:/opt/data
  #     - ./volumes/code:/opt/code
  #     - spark_data:/opt/data1
  #   environment:
  #     - SPARK_MODE=worker
  #     - SPARK_MASTER_URL=spark://spark-master:7077
  #     - SPARK_WORKER_MEMORY=4G
  #     - SPARK_WORKER_CORES=2
  #     - SPARK_RPC_AUTHENTICATION_ENABLED=no
  #     - SPARK_RPC_ENCRYPTION_ENABLED=no
  #     - SPARK_LOCAL_STORAGE_ENCRYPTION_ENABLED=no
  #     - SPARK_SSL_ENABLED=no
  #   restart: always
  #   depends_on:
  #     - spark-master

  zeppelin:
    build:
      context: docker/
      dockerfile: Dockerfile_zeppelin
    container_name: zeppelin
    user: root
    ports:
      - '9090:8080'
    volumes:
      - /mnt/c/git/sparkproject/spark/volumes/data:/opt/data
#      - ./volumes/data:/opt/data
      - ./volumes/code:/opt/code
      - ./volumes/spark:/bitnami/spark
      - ./volumes/notebook:/opt/zeppelin/notebook
      - spark_data:/opt/data1
    environment:
      - MASTER=spark://spark-master:7077
      - SPARK_HOME=/opt/bitnami/spark
      - SPARK_MASTER=spark://spark-master:7077
      - ZEPPELIN_INTERPRETER_OUTPUT_LIMIT=409600
    depends_on:
      - spark-master
      - spark-worker-1
      # - spark-worker-2
    restart: unless-stopped

volumes:
  spark_data: # Docker volume

dockerfile_spark:

FROM docker.io/bitnamilegacy/spark:3.1.2

USER root

COPY requirements.txt /tmp/

# RUN apt-get update -y
# Switch Debian Buster to archive repos
RUN sed -i 's/deb.debian.org/archive.debian.org/g' /etc/apt/sources.list && \
    sed -i 's/security.debian.org/archive.debian.org/g' /etc/apt/sources.list && \
    sed -i '/stretch-updates/d' /etc/apt/sources.list && \
    sed -i '/buster-updates/d' /etc/apt/sources.list

# your current command should work now
# RUN apt-get clean && \
#    apt-get update -y || (sleep 5 && apt-get update -y)

RUN pip3 install -r /tmp/requirements.txt

dockerfile_zeppelin:

FROM docker.io/bitnamilegacy/spark:3.1.2 AS spark
FROM docker.io/apache/zeppelin:0.10.0 AS zeppelin
COPY --from=spark /opt/bitnami/spark/ /opt/bitnami/spark 

USER root

COPY requirements.txt /tmp/

RUN apt-get update -y
RUN apt-get install libssl-dev libbz2-dev zlib1g-dev openssl build-essential wget -y
RUN cd /usr/src && \
    wget https://www.python.org/ftp/python/3.6.15/Python-3.6.15.tgz && \
    tar xzvf Python-3.6.15.tgz && \
    cd Python-3.6.15 && \
    ./configure && \
    make install
RUN rm -rf /opt/conda/envs/python_3_with_R/bin/python3.7 && \
    cp /usr/src/Python-3.6.15/python  /opt/conda/envs/python_3_with_R/bin/python3.7
RUN python -m pip install --upgrade pip
RUN pip3 install -r /tmp/requirements.txt

Then, I’m trying to read a CSV into DataFrame and save it back via


%spark.pyspark
df.write.format('parquet').mode('overwrite').save("/opt/data/sf-fire-calls.parquet")

And it always fails with:


    :
    :
    at java.lang.Thread.run(Thread.java:748) Caused by: org.apache.spark.SparkException: 
         Job aborted due to stage failure: Task 0 in stage 6.0 failed 4 times, most recent failure: Lost task 0.3 in stage 6.0 (TID 43) (172.18.0.3 executor 0):
         ExitCodeException exitCode=1: chmod: changing permissions of '/opt/data/sf-fire-calls.parquet/_temporary/0/_temporary/attempt_202610041025578200208790666384743_0006_m_000000_43': 
         Operation not permitted
    at org.apache.hadoop.util.Shell.runCommand(Shell.java:1008)

I am running docker on Windows 10 such as admin user.I’m running docker-compose script from WSL ubuntu distro, as admin user

I also tried running docker-compose script from Windows command line as admin user, but it still fails to create “temporary directories”.

It doesn’t matter what your user is on Windows or in the WSL distribution. What matters is the user inside the container and whether it has access to specific files or not.

I looks like you mount files from the C:\git\***. That is a Windows filesystem and I assume the process in a Linux container tries to change permissions like it should on Linux, which will probably not work. I would store the data in the WSL distribution anyway which makes it faster and the filesystem will be compatible with Linux so overwriting the “MODE” would most likely work.

Small note about changing the permission of files coming from a windows drive:

By default, WSL distributions mount the Windows file systems with disabled metadata support, but it can be enabled per distro:
https://learn.microsoft.com/en-us/windows/wsl/wsl-config#automount-options

Since you haven’t mentioned Docker Desktop, I assume docker runs in your Ubuntu distro. You could try enabling the metadata, and see if it does the job. Though, to be honest, I would follow @rimelek’s advice and place the data directly on the disk of your Ubuntu distribution - it is the better solution.