2
  1. I downloaded apache spark docker image from here.

  2. I then found out that SPARK_NO_DAEMONIZE should be set to TRUE - which I did by 'bash'ing into Docker using the following command

     docker run -ti --name spark apache/spark:v3.3.0 bash
    
     export SPARK_NO_DAEMONIZE=true
    
  3. I then tried starting spark - '/opt/spark/sbin/start-master.sh' and then got the error

     sh-5.1$ /opt/spark/sbin/start-master.sh
     mkdir: cannot create directory ‘/opt/spark/logs’: Permission denied
     chown: cannot access '/opt/spark/logs': No such file or directory
     starting org.apache.spark.deploy.master.Master, logging to
       /opt/spark/logs/spark--org.apache.spark.deploy.master.Master-1-   
       aaea1d8bfe7c.out
     Spark Command: /usr/local/openjdk-11/bin/java -cp   
     /opt/spark/conf:/opt/spark/jars/* -Xmx1g 
     org.apache.spark.deploy.master.Master --host aaea1d8bfe7c --port 7077 --  
     webui-port 8080
    

I understand from the 'Dockerfile' that user '185' runs everything in there. Unfortunately, I don't yet understand how to enable root user in there so that I can change the permissions or creating log directory.

Could someone please suggest whether I am missing something?

p.s. I don't wish to run spark using docker-compose.yml I want to run a single cluster

1
  • Try adding user: root after image in docker compose file. Commented May 29, 2023 at 12:00

1 Answer 1

5

You can override the user that runs inside the container:

docker run -ti --user 0 --name spark apache/spark:v3.3.0 bash

You are then root inside the container.

If you want to do it through a Dockerfile instead, these are the steps:

  1. Create a Dockerfile as:
FROM apache/spark:v3.3.0

USER root

RUN mkdir -p /opt/spark/logs && chmod a+wr /opt/spark/logs

USER 185

ENV SPARK_NO_DAEMONIZE=true

CMD ["/opt/spark/sbin/start-master.sh"]
  1. Build the image
docker build -t "testspark" .
  1. Run the container
docker run -ti --rm testspark
Sign up to request clarification or add additional context in comments.

1 Comment

This is what I would probably end up writing in my Dockerfile but I would also probably add some minor things such as nano :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.