dockerDev
Dockerized Development Environment for Spark+Scala+mvn/sbt+..., python, and R for specific open-source projects.
This is currently being developed for various projects involving Spark, Scala, R, Python, etc.
Some concrete open-source projects using these docker containers that are avialable directly dockerhub at:
include:
For Spark 3.x use tag spark3x and for Spark 2.x use tag spark2x:
-
Spark/Scala: with docker pull lamastex/dockerdev:spark3x
-
Spark/Scala: with docker pull lamastex/dockerdev:spark2x
-
Python:
-
R: with docker pull lamastex/r-base-rvest
-
Haskell: with docker pull lamastex/haskell-pinot
-
Rust: with docker pull lamastex/rust-mdbook
- https:github.com/lamastex/scalable-data-science/tree/master/books#mdbook
-
databricksCLI: with docker pull lamastex/python-dbcli
-
when multi-language development is needed just start FROM a given container and RUN as needed:
- For Spark/Scala 3.x with Python 3.x for twarc:
docker pull lamastex/dockerdev:spark3x-py3 built from spark3x-py3.Dockerfile.
- For Spark/Scala 3.x with Python 3.x for magellan:
docker pull lamastex/dockerdev:spark3x-py3 built from spark3x-py3.Dockerfile.
- The largest union of all development environments will have the
latest tag. Currently, lamastex/dockerdev:latest is lamastex/dockerdev:spark3x-py3
Build latest from Dockerfile
Currently Dockerfile is for Spark 3.x. with Python 3 for twarc.
docker build -t lamastex/dockerdev:latest .
To build and push to dockerhub
- first, create repos in dockerhub
- second, follow the next commands for pushing the Spark 2.x compliant image built from
spark2x.Dockerfile into dockerhub:
docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: dockerUserName
Password:
Login Succeeded
docker build -t lamastex/dockerdev:spark2x -f spark2x.Dockerfile .
docker push lamastex/dockerdev:spark2x
Run
Run a docker container for the project as daemon and execute into it with bash.
$ pwd
~/all/git/
$ docker run --rm -d -it --name=spark-gdelt --mount type=bind,source=${HOME}/all/git,destination=/root/GIT -p 4040:4040 lamastex/dockerdev:latest
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d838fdc21f5a lamastex/dockerdev:latest "/bin/bash" 3 seconds ago Up 3 seconds 4040/tcp spark-gdelt
$ docker exec -it spark-gdelt /bin/bash
Code in spark-shell
For example, if the spark project is aamend/spark-gdelt:
root@d838fdc21f5a:~/GIT/aamend/spark-gdelt# pwd
/root/GIT/aamend/spark-gdelt
root@d838fdc21f5a:~/GIT/aamend/spark-gdelt# mvn verify
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:28 min
[INFO] Finished at: 2020-03-12T08:58:23Z
[INFO] ------------------------------------------------------------------------
root@d838fdc21f5a:~/GIT/aamend/spark-gdelt# cp target/spark-gdelt-2.2-SNAPSHOT.jar ../../../spark-2.4.4-bin-hadoop2.7/jars/
After packaging needed jar and adding it to the jars folder, one can start coding in spark across all relevant git repos, as follows:
root@d838fdc21f5a:~/GIT/aamend/spark-gdelt# cd ../../
root@d838fdc21f5a:~/GIT/aamend# pwd
/root/GIT
root@d838fdc21f5a:~/GIT/aamend# spark-shell
09:07:36,398 WARN org.apache.hadoop.util.NativeCodeLoader: 62 - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).
Spark context Web UI available at http://d838fdc21f5a:4040
Spark context available as 'sc' (master = local[*], app id = local-1584004065812).
Spark session available as 'spark'.
Welcome to
____ __
/ __/__ ___ _____/ /__
_\ \/ _ \/ _ `/ __/ '_/
/___/ .__/\_,_/_/ /_/\_\ version 2.4.4
/_/
Using Scala version 2.11.12 (OpenJDK 64-Bit Server VM, Java 1.8.0_242)
Type in expressions to have them evaluated.
Type :help for more information.
scala>
You can pass extra arguments to spark-shell. For example, to set file-encoding to utf-8, do:
spark-shell --conf "spark.driver.extraJavaOptions=-Dfile.encoding=utf-8"
Stopping or starting the container
When you want to stop or start the container just do docker stop spark-gdelt or docker start spark-gdelt and then docker exec -it spark-gdelt /bin/bash to get inside the running container.
Note that docker kill will stop and remove the container. See docker help for more details.
Commiting mvn downloads to a container
This is useful if you don't want to keep downloading from mvn when pom/xml is fixed for dev cycle.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:45 min
[INFO] Finished at: 2020-07-04T14:11:03Z
[INFO] ------------------------------------------------------------------------
root@bb0d1714cde9:~/GIT/spark-gdelt# exit
$ ls
aamend dockerDev mob-spark spark-gdelt
apache emm-newsbrief-rvest mrs2 tilowiklund
computational-statistical-experiments lamastex.github.io private
distributed-histogram-trees magellan scalable-data-science
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bb0d1714cde9 lamastex/dockerdev:latest "/bin/bash" 23 minutes ago Up 23 minutes 0.0.0.0:4040->4040/tcp spark-gdelt
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bb0d1714cde9 lamastex/dockerdev:latest "/bin/bash" 27 minutes ago Up 27 minutes 0.0.0.0:4040->4040/tcp spark-gdelt
$ docker commit spark-gdelt lamastex/dockerdev:20200407-spark-gdelt
sha256:3132086a46e04316fb280df9f31d6f975d53ebd637edeaa5ad6a686dfd058c29
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
lamastex/dockerdev 20200407-spark-gdelt 3132086a46e0 12 seconds ago 1.54GB
lamastex/dockerdev latest 9dd569021915 35 minutes ago 1.27GB
ubuntu 18.04 8e4ce0a6ce69 2 weeks ago 64.2MB
hello-world latest bf756fb1ae65 6 months ago 13.3kB
$ docker kill spark-gdelt
spark-gdelt
$ docker run --rm -it --mount type=bind,source=${HOME}/all/git,destination=/root/GIT -p 4040:4040 lamastex/dockerdev:20200407-spark-gdelt
root@9f2b5d6cb084:~# cd GIT/spark-gdelt/
root@9f2b5d6cb084:~/GIT/spark-gdelt# mvn verify # should proceed from the cached jars
Note that if you run the container as above then you have to change the port on the host-side to have multiple running containers.
This is useful sometimes. Alternatively, you can run the container in daemon mode as follows.
If you want to launch in deamon mode with a name and execute into the same running container with a name then do:
docker run --rm -it -d --name=20200407-spark-gdelt --mount type=bind,source=${HOME}/all/git,destination=/root/GIT -p 4040:4040 lamastex/dockerdev:20200407-spark-gdelt
Note that if you do not use --rm flag then the docker container will not be removed when you exit the container.
Python docker dev environment
This python-findata.Dockerfile is for python dev environemnt for the following packages:
To Use:
docker pull lamastex/python-findata
docker run --rm -it --mount type=bind,source=${HOME}/all/git,destination=/root/GIT lamastex/python-findata /bin/bash
This python-twarc.Dockerfile is for python dev environemnt for the following packages:
To Use:
In interactive mode after starting in daemon mode:
docker pull lamastex/python-twarc:latest
docker run --rm -d -it --name=mep-pytwarc --mount type=bind,source=${HOME}/all/git,destination=/root/GIT lamastex/python-twarc:latest
$ docker exec -it mep-pytwarc /bin/bash
To Build such docker containers:
docker build -t lamastex/python-findata -f python-findata.Dockerfile .
docker build -t lamastex/python-twarc -f python-twarc.Dockerfile .
To push them to docker Hub so they cna be pulled:
docker push lamastex/python-twarc:latest
Haskell dockerDev environment
Quick commands to build, push, pull (only need to be done once) and run and execute with local directory binds.
docker build -t lamastex/haskell-pinot:latest -f haskell-pinot.Dockerfile .
docker push lamastex/haskell-pinot
docker pull lamastex/haskell-pinot
docker run --rm -d -it --name=haskell-pinot --mount type=bind,source=${HOME}/all/git,destination=/root/GIT lamastex/haskell-pinot:latest
docker exec -it haskell-pinot /bin/bash
Go to the right directory with local git repos and launch docker container for haskell-pinot work.
$ cd ~/all/git/
$ docker run --rm -d -it --name=haskell-pinot --mount type=bind,source=${HOME}/all/git,destination=/root/GIT lamastex/haskell-pinot:latest
d8abf881e058d46abd69157a33441e3fbf95ef28e7d9f18252cff79949d0f05f
$ docker exec -it haskell-pinot /bin/bash
root@d8abf881e058:~# echo $PINOT_DIR
/root/tilowiklund/pinot
root@d8abf881e058:~# cd $PINOT_DIR
root@d8abf881e058:~/tilowiklund/pinot# pwd
/root/tilowiklund/pinot
root@d8abf881e058:~/tilowiklund/pinot# stack exec pinot
Missing: (-f|--from FROM) (-t|--to TO) INPUTS...
Usage: pinot (-f|--from FROM) (-t|--to TO) INPUTS... [-o|--out OUTPUT]
[-c|--keep-going] [-R|--extra-resource-path ARG]
Convert between different notebook formats
root@d8abf881e058:~/tilowiklund/pinot#
Rust dockerDev environment for mdbook
Quick commands to build, push, pull (only need to be done once) and run and execute with local directory binds.