├── .dockerignore ├── .gitignore ├── Dockerfile.spark-2.1.2 ├── Dockerfile.spark-2.2.1 ├── LICENSE ├── README.md ├── examples ├── observatory.sh └── timeusage.sh └── run.sh /.dockerignore: -------------------------------------------------------------------------------- 1 | *.md 2 | .gitignore 3 | examples 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.sw? 2 | .idea 3 | -------------------------------------------------------------------------------- /Dockerfile.spark-2.1.2: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-alpine 2 | 3 | LABEL maintainer="Arseniy Tashoyan " 4 | 5 | RUN apk --update add git curl tar bash ncurses && \ 6 | rm -rf /var/lib/apt/lists/* && \ 7 | rm /var/cache/apk/* 8 | 9 | ARG SBT_VERSION=1.1.0 10 | ARG SBT_HOME=/usr/local/sbt 11 | RUN curl -sL "https://github.com/sbt/sbt/releases/download/v$SBT_VERSION/sbt-$SBT_VERSION.tgz" | tar -xz -C /usr/local 12 | 13 | ARG SPARK_VERSION=2.1.2 14 | ARG SPARK_HOME=/usr/local/spark-$SPARK_VERSION-bin-hadoop2.7 15 | RUN curl -sL "http://www-us.apache.org/dist/spark/spark-$SPARK_VERSION/spark-$SPARK_VERSION-bin-hadoop2.7.tgz" | tar -xz -C /usr/local 16 | 17 | ENV PATH $PATH:$SBT_HOME/bin:$SPARK_HOME/bin 18 | 19 | ENV SPARK_MASTER local[*] 20 | 21 | ENV SPARK_DRIVER_PORT 5001 22 | ENV SPARK_UI_PORT 5002 23 | ENV SPARK_BLOCKMGR_PORT 5003 24 | EXPOSE $SPARK_DRIVER_PORT $SPARK_UI_PORT $SPARK_BLOCKMGR_PORT 25 | 26 | COPY run.sh / 27 | CMD ./run.sh 28 | -------------------------------------------------------------------------------- /Dockerfile.spark-2.2.1: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-alpine 2 | 3 | LABEL maintainer="Arseniy Tashoyan " 4 | 5 | RUN apk --update add git curl tar bash ncurses && \ 6 | rm -rf /var/lib/apt/lists/* && \ 7 | rm /var/cache/apk/* 8 | 9 | ARG SBT_VERSION=1.1.0 10 | ARG SBT_HOME=/usr/local/sbt 11 | RUN curl -sL "https://github.com/sbt/sbt/releases/download/v$SBT_VERSION/sbt-$SBT_VERSION.tgz" | tar -xz -C /usr/local 12 | 13 | ARG SPARK_VERSION=2.2.1 14 | ARG SPARK_HOME=/usr/local/spark-$SPARK_VERSION-bin-hadoop2.7 15 | RUN curl -sL "http://www-us.apache.org/dist/spark/spark-$SPARK_VERSION/spark-$SPARK_VERSION-bin-hadoop2.7.tgz" | tar -xz -C /usr/local 16 | 17 | ENV PATH $PATH:$SBT_HOME/bin:$SPARK_HOME/bin 18 | 19 | ENV SPARK_MASTER local[*] 20 | 21 | ENV SPARK_DRIVER_PORT 5001 22 | ENV SPARK_UI_PORT 5002 23 | ENV SPARK_BLOCKMGR_PORT 5003 24 | EXPOSE $SPARK_DRIVER_PORT $SPARK_UI_PORT $SPARK_BLOCKMGR_PORT 25 | 26 | COPY run.sh / 27 | CMD ./run.sh 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | 204 | ======================================================================= 205 | Apache Spark Subcomponents: 206 | 207 | The Apache Spark project contains subcomponents with separate copyright 208 | notices and license terms. Your use of the source code for the these 209 | subcomponents is subject to the terms and conditions of the following 210 | licenses. 211 | 212 | 213 | ======================================================================== 214 | For heapq (pyspark/heapq3.py): 215 | ======================================================================== 216 | 217 | See license/LICENSE-heapq.txt 218 | 219 | ======================================================================== 220 | For SnapTree: 221 | ======================================================================== 222 | 223 | See license/LICENSE-SnapTree.txt 224 | 225 | ======================================================================== 226 | For jbcrypt: 227 | ======================================================================== 228 | 229 | See license/LICENSE-jbcrypt.txt 230 | 231 | ======================================================================== 232 | BSD-style licenses 233 | ======================================================================== 234 | 235 | The following components are provided under a BSD-style license. See project link for details. 236 | The text of each license is also included at licenses/LICENSE-[project].txt. 237 | 238 | (BSD 3 Clause) netlib core (com.github.fommil.netlib:core:1.1.2 - https://github.com/fommil/netlib-java/core) 239 | (BSD 3 Clause) JPMML-Model (org.jpmml:pmml-model:1.2.7 - https://github.com/jpmml/jpmml-model) 240 | (BSD License) AntLR Parser Generator (antlr:antlr:2.7.7 - http://www.antlr.org/) 241 | (BSD License) ANTLR 4.5.2-1 (org.antlr:antlr4:4.5.2-1 - http://wwww.antlr.org/) 242 | (BSD licence) ANTLR ST4 4.0.4 (org.antlr:ST4:4.0.4 - http://www.stringtemplate.org) 243 | (BSD licence) ANTLR StringTemplate (org.antlr:stringtemplate:3.2.1 - http://www.stringtemplate.org) 244 | (BSD License) Javolution (javolution:javolution:5.5.1 - http://javolution.org) 245 | (BSD) JLine (jline:jline:0.9.94 - http://jline.sourceforge.net) 246 | (BSD) ParaNamer Core (com.thoughtworks.paranamer:paranamer:2.3 - http://paranamer.codehaus.org/paranamer) 247 | (BSD) ParaNamer Core (com.thoughtworks.paranamer:paranamer:2.6 - http://paranamer.codehaus.org/paranamer) 248 | (BSD 3 Clause) Scala (http://www.scala-lang.org/download/#License) 249 | (Interpreter classes (all .scala files in repl/src/main/scala 250 | except for Main.Scala, SparkHelper.scala and ExecutorClassLoader.scala), 251 | and for SerializableMapWrapper in JavaUtils.scala) 252 | (BSD-like) Scala Actors library (org.scala-lang:scala-actors:2.11.7 - http://www.scala-lang.org/) 253 | (BSD-like) Scala Compiler (org.scala-lang:scala-compiler:2.11.7 - http://www.scala-lang.org/) 254 | (BSD-like) Scala Compiler (org.scala-lang:scala-reflect:2.11.7 - http://www.scala-lang.org/) 255 | (BSD-like) Scala Library (org.scala-lang:scala-library:2.11.7 - http://www.scala-lang.org/) 256 | (BSD-like) Scalap (org.scala-lang:scalap:2.11.7 - http://www.scala-lang.org/) 257 | (BSD-style) scalacheck (org.scalacheck:scalacheck_2.11:1.10.0 - http://www.scalacheck.org) 258 | (BSD-style) spire (org.spire-math:spire_2.11:0.7.1 - http://spire-math.org) 259 | (BSD-style) spire-macros (org.spire-math:spire-macros_2.11:0.7.1 - http://spire-math.org) 260 | (New BSD License) Kryo (com.esotericsoftware:kryo:3.0.3 - https://github.com/EsotericSoftware/kryo) 261 | (New BSD License) MinLog (com.esotericsoftware:minlog:1.3.0 - https://github.com/EsotericSoftware/minlog) 262 | (New BSD license) Protocol Buffer Java API (com.google.protobuf:protobuf-java:2.5.0 - http://code.google.com/p/protobuf) 263 | (New BSD license) Protocol Buffer Java API (org.spark-project.protobuf:protobuf-java:2.4.1-shaded - http://code.google.com/p/protobuf) 264 | (The BSD License) Fortran to Java ARPACK (net.sourceforge.f2j:arpack_combined_all:0.1 - http://f2j.sourceforge.net) 265 | (The BSD License) xmlenc Library (xmlenc:xmlenc:0.52 - http://xmlenc.sourceforge.net) 266 | (The New BSD License) Py4J (net.sf.py4j:py4j:0.10.1 - http://py4j.sourceforge.net/) 267 | (Two-clause BSD-style license) JUnit-Interface (com.novocode:junit-interface:0.10 - http://github.com/szeiger/junit-interface/) 268 | (BSD licence) sbt and sbt-launch-lib.bash 269 | (BSD 3 Clause) d3.min.js (https://github.com/mbostock/d3/blob/master/LICENSE) 270 | (BSD 3 Clause) DPark (https://github.com/douban/dpark/blob/master/LICENSE) 271 | (BSD 3 Clause) CloudPickle (https://github.com/cloudpipe/cloudpickle/blob/master/LICENSE) 272 | 273 | ======================================================================== 274 | MIT licenses 275 | ======================================================================== 276 | 277 | The following components are provided under the MIT License. See project link for details. 278 | The text of each license is also included at licenses/LICENSE-[project].txt. 279 | 280 | (MIT License) JCL 1.1.1 implemented over SLF4J (org.slf4j:jcl-over-slf4j:1.7.5 - http://www.slf4j.org) 281 | (MIT License) JUL to SLF4J bridge (org.slf4j:jul-to-slf4j:1.7.5 - http://www.slf4j.org) 282 | (MIT License) SLF4J API Module (org.slf4j:slf4j-api:1.7.5 - http://www.slf4j.org) 283 | (MIT License) SLF4J LOG4J-12 Binding (org.slf4j:slf4j-log4j12:1.7.5 - http://www.slf4j.org) 284 | (MIT License) pyrolite (org.spark-project:pyrolite:2.0.1 - http://pythonhosted.org/Pyro4/) 285 | (MIT License) scopt (com.github.scopt:scopt_2.11:3.2.0 - https://github.com/scopt/scopt) 286 | (The MIT License) Mockito (org.mockito:mockito-core:1.9.5 - http://www.mockito.org) 287 | (MIT License) jquery (https://jquery.org/license/) 288 | (MIT License) AnchorJS (https://github.com/bryanbraun/anchorjs) 289 | (MIT License) graphlib-dot (https://github.com/cpettitt/graphlib-dot) 290 | (MIT License) dagre-d3 (https://github.com/cpettitt/dagre-d3) 291 | (MIT License) sorttable (https://github.com/stuartlangridge/sorttable) 292 | (MIT License) boto (https://github.com/boto/boto/blob/develop/LICENSE) 293 | (MIT License) datatables (http://datatables.net/license) 294 | (MIT License) mustache (https://github.com/mustache/mustache/blob/master/LICENSE) 295 | (MIT License) cookies (http://code.google.com/p/cookies/wiki/License) 296 | (MIT License) blockUI (http://jquery.malsup.com/block/) 297 | (MIT License) RowsGroup (http://datatables.net/license/mit) 298 | (MIT License) jsonFormatter (http://www.jqueryscript.net/other/jQuery-Plugin-For-Pretty-JSON-Formatting-jsonFormatter.html) 299 | (MIT License) modernizr (https://github.com/Modernizr/Modernizr/blob/master/LICENSE) 300 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # docker-spark-submit 2 | 3 | ## Docker image to run Spark applications 4 | 5 | Performs the following tasks: 6 | 1. Gets the source code from the SCM repository 7 | 1. Builds the application 8 | 1. Runs the application by submitting it to the Spark cluster 9 | 10 | At present, only Git is supported for SCM and only Sbt is supported for build. Both `git` and `sbt` commands are present in the PATH within the image. 11 | 12 | Run example: 13 | ``` 14 | docker run \ 15 | -ti \ 16 | --rm \ 17 | -p 5000-5010:5000-5010 \ 18 | -e SCM_URL="https://github.com/mylogin/project.git" \ 19 | -e SPARK_MASTER="spark://my.master.com:7077" \ 20 | -e SPARK_DRIVER_HOST="192.168.1.2" \ 21 | -e MAIN_CLASS="Main" \ 22 | tashoyan/docker-spark-submit:spark-2.2.1 23 | ``` 24 | 25 | Image at DockerHub: [docker-spark-submit](https://hub.docker.com/r/tashoyan/docker-spark-submit/). 26 | 27 | ## Important command line arguments 28 | 29 | `-p 5000-5010:5000-5010` 30 | 31 | You have to publish this range of network ports. Spark driver program and Spark executors use these ports for communication. 32 | 33 | `-e SPARK_DRIVER_HOST="host.machine.address"` 34 | 35 | You have to specify here the network address of the host machine where the container will be running. Spark cluster nodes 36 | should be able to resolve this address. This is necessary for communication between executors and the driver program. 37 | For detailed technical information see [SPARK-4563](https://issues.apache.org/jira/browse/SPARK-4563). 38 | 39 | ## Command line arguments 40 | 41 | Command line arguments are passed via environment variables for `docker` command: `-e VAR="value"`. Here is the full list: 42 | 43 | | Name | Mandatory? | Meaning | Default value | 44 | | ---- |:----------:| ------- | ------------- | 45 | | SCM_URL | Yes | URL to get source code from. | N/A | 46 | | SCM_BRANCH | No | SCM branch to checkout. | master | 47 | | PROJECT_SUBDIR | No | A relative directory to the root of the SCM working copy.
If specified, then the build will be executed in this directory, rather than in the root directory. | N/A | 48 | | BUILD_COMMAND | No | Command to build the application. | `sbt 'set test in assembly := {}' clean assembly`
Means: build fat-jar using sbt-assembly plugin skipping the tests. | 49 | | SPARK_MASTER | No | Spark master URL. | `local[*]` | 50 | | SPARK_CONF | No | Arbitrary Spark configuration settings, like:
`--conf spark.executor.memory=2g --conf spark.driver.cores=2` | Empty | 51 | | SPARK_DRIVER_HOST | Yes | Value of the `spark.driver.host` configuration parameter.
Must be set to the network address of the machine hosting the container. Must be accessible from Spark nodes. | N/A | 52 | | JAR_FILE | No | Path to the application jar file. Relative to the build directory.
If not specified, the jar file will be automatically found under `target/` subdirectory of the build directory. | N/A | 53 | | MAIN_CLASS | Yes | Main class of the application to run. | N/A | 54 | | APP_ARGS | No | Application arguments. | Empty | 55 | | http_proxy, https_proxy | No | Specify when running behind a proxy. | Empty, no proxy | 56 | 57 | ## Working with data 58 | 59 | If your Spark program requires some data for processing, you can add the data to the container by specifying a volume: 60 | 61 | ``` 62 | docker run \ 63 | -ti \ 64 | --rm \ 65 | -v /data:/data \ 66 | -p 5000-5010:5000-5010 \ 67 | -e SCM_URL="https://github.com/mylogin/project.git" \ 68 | -e SPARK_MASTER="spark://my.master.com:7077" \ 69 | -e SPARK_DRIVER_HOST="192.168.1.2" \ 70 | -e MAIN_CLASS="Main" \ 71 | tashoyan/docker-spark-submit:spark-2.2.1 72 | ``` 73 | 74 | ## Available image tags 75 | 76 | Image tags correspond to Spark versions. Choose the tag based on the version of your Spark cluster. 77 | The following tags are available: 78 | * spark-2.2.1 79 | * spark-2.1.2 80 | 81 | ## Building the image 82 | 83 | Build the image: 84 | ``` 85 | docker build \ 86 | -t tashoyan/docker-spark-submit:spark-2.2.1 \ 87 | -f Dockerfile.spark-2.2.1 \ 88 | . 89 | ``` 90 | When building on a machine behind proxy, specify `http_proxy` environment variable: 91 | ``` 92 | docker build \ 93 | --build-arg http_proxy=http://my.proxy.com:8080 \ 94 | -t tashoyan/docker-spark-submit:spark-2.2.1 \ 95 | -f Dockerfile.spark-2.2.1 \ 96 | . 97 | ``` 98 | 99 | ## License 100 | 101 | Apache 2.0 license. 102 | -------------------------------------------------------------------------------- /examples/observatory.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -o nounset 4 | set -o errexit 5 | 6 | ip_addr="$(ifconfig | grep -Eo 'inet (addr:)?([0-9]+\.){3}[0-9]+' | grep -Eo '([0-9]+\.){3}[0-9]+' | grep -v '127.0.0.1' | grep -v '172.17.0.1')" 7 | if test -z "$ip_addr" 8 | then 9 | echo "Cannot determine the machine IP address." 10 | exit 1 11 | fi 12 | 13 | docker run \ 14 | -ti \ 15 | --rm \ 16 | -p 5000-5010:5000-5010 \ 17 | --name spark-submit \ 18 | -v /data:/data \ 19 | -e SCM_URL="https://github.com/tashoyan/sc.git" \ 20 | -e SCM_BRANCH="spark" \ 21 | -e PROJECT_SUBDIR="05-functional-programming-in-scala-capstone/observatory" \ 22 | -e SPARK_MASTER="spark://$ip_addr:7077" \ 23 | -e MAIN_CLASS="image.Generator0S" \ 24 | -e SPARK_DRIVER_HOST="$ip_addr" \ 25 | -e https_proxy="http://web-proxy.gre.hpecorp.net:8080" \ 26 | tashoyan/docker-spark-submit:spark-2.2.1 27 | -------------------------------------------------------------------------------- /examples/timeusage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -o nounset 4 | set -o errexit 5 | 6 | ip_addr="$(ifconfig | grep -Eo 'inet (addr:)?([0-9]+\.){3}[0-9]+' | grep -Eo '([0-9]+\.){3}[0-9]+' | grep -v '127.0.0.1' | grep -v '172.17.0.1')" 7 | if test -z "$ip_addr" 8 | then 9 | echo "Cannot determine the machine IP address." 10 | exit 1 11 | fi 12 | 13 | docker run \ 14 | -ti \ 15 | --rm \ 16 | -p 5000-5010:5000-5010 \ 17 | --name spark-submit \ 18 | -v /data:/data \ 19 | -e SCM_URL="https://github.com/tashoyan/sc.git" \ 20 | -e SCM_BRANCH="spark" \ 21 | -e PROJECT_SUBDIR="04-big-data-analysis-with-scala-and-spark/04-timeusage/timeusage" \ 22 | -e BUILD_COMMAND="sbt clean package" \ 23 | -e SPARK_MASTER="spark://$ip_addr:7077" \ 24 | -e SPARK_CONF="--conf spark.executor.memory=2g --conf spark.driver.cores=2" \ 25 | -e JAR_FILE="target/scala-2.11/bigdata-timeusage_2.11-0.1-SNAPSHOT.jar" \ 26 | -e MAIN_CLASS="timeusage.TimeUsage" \ 27 | -e APP_ARGS="aaa bbb" \ 28 | -e SPARK_DRIVER_HOST="$ip_addr" \ 29 | -e https_proxy="http://web-proxy.gre.hpecorp.net:8080" \ 30 | tashoyan/docker-spark-submit:spark-2.2.1 31 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -o errexit 4 | 5 | test -z "$SCM_URL" && ( echo "SCM_URL is not set; exiting" ; exit 1 ) 6 | test -z "$SPARK_MASTER" && ( echo "SPARK_MASTER is not set; exiting" ; exit 1 ) 7 | test -z "$MAIN_CLASS" && ( echo "MAIN_CLASS is not set; exiting" ; exit 1 ) 8 | test -z "$SPARK_DRIVER_HOST" && ( echo "SPARK_DRIVER_HOST is not set; exiting" ; exit 1 ) 9 | test -z "$SPARK_DRIVER_PORT" && ( echo "SPARK_DRIVER_PORT is not set; exiting" ; exit 1 ) 10 | test -z "$SPARK_UI_PORT" && ( echo "SPARK_UI_PORT is not set; exiting" ; exit 1 ) 11 | test -z "$SPARK_BLOCKMGR_PORT" && ( echo "SPARK_BLOCKMGR_PORT is not set; exiting" ; exit 1 ) 12 | 13 | echo "Cloning the repository: $SCM_URL" 14 | git clone "$SCM_URL" 15 | project_git="${SCM_URL##*/}" 16 | project_dir="${project_git%.git}" 17 | if test -n "$SCM_BRANCH" 18 | then 19 | cd "$project_dir" 20 | git checkout "$SCM_BRANCH" 21 | cd - 22 | fi 23 | 24 | echo "Building the jar" 25 | if test -z "$PROJECT_SUBDIR" 26 | then 27 | cd "$project_dir" 28 | else 29 | cd "$project_dir/$PROJECT_SUBDIR" 30 | fi 31 | echo "Building at: $(pwd)" 32 | 33 | if test -z "$BUILD_COMMAND" 34 | then 35 | build_command="sbt 'set test in assembly := {}' clean assembly" 36 | else 37 | build_command="$BUILD_COMMAND" 38 | fi 39 | echo "Building with command: $build_command" 40 | eval $build_command 41 | 42 | ip_addr="$(ifconfig | grep -Eo 'inet (addr:)?([0-9]+\.){3}[0-9]+' | grep -Eo '([0-9]+\.){3}[0-9]+' | grep -v '127.0.0.1' | head)" 43 | if test -z "$ip_addr" 44 | then 45 | echo "Cannot determine the container IP address." 46 | exit 1 47 | fi 48 | 49 | if test -z "$JAR_FILE" 50 | then 51 | jarfile="$(ls target/scala-*/*.jar)" 52 | else 53 | jarfile="$JAR_FILE" 54 | fi 55 | if ! test -f "$jarfile" 56 | then 57 | echo "Jar file not found or not a single file: $jarfile" 58 | echo "You can specify jar file explicitly: -e JAR_FILE=/path/to/file" 59 | exit 1 60 | fi 61 | 62 | echo "Submitting jar: $jarfile" 63 | echo "Application main class: $MAIN_CLASS" 64 | echo "Application arguments: $APP_ARGS" 65 | echo "Spark master: $SPARK_MASTER" 66 | echo "Spark driver host: $SPARK_DRIVER_HOST" 67 | echo "Spark driver port: $SPARK_DRIVER_PORT" 68 | echo "Spark UI port: $SPARK_UI_PORT" 69 | echo "Spark block manager port: $SPARK_BLOCKMGR_PORT" 70 | echo "Spark configuration settings: $SPARK_CONF" 71 | spark-submit \ 72 | --master "$SPARK_MASTER" \ 73 | --conf spark.driver.bindAddress="$ip_addr" \ 74 | --conf spark.driver.host="$SPARK_DRIVER_HOST" \ 75 | --conf spark.driver.port=$SPARK_DRIVER_PORT \ 76 | --conf spark.ui.port=$SPARK_UI_PORT \ 77 | --conf spark.blockManager.port=$SPARK_BLOCKMGR_PORT \ 78 | $SPARK_CONF \ 79 | --class "$MAIN_CLASS" \ 80 | "$jarfile" \ 81 | $APP_ARGS 82 | --------------------------------------------------------------------------------