Docker允许我们执行Scala应用程序。 在这里,我们将演示如何创建一个Scala文件,并使用docker进行执行,此示例包括以下步骤。
$ mkdir - /home/zyiz/docker/scala-docker-app
$ cd /home/zyiz/docker/scala-docker-app
Dockerfile
的 Dockerfile 文件FROM williamyeh/java7 MAINTAINER Hema (zyiz.net@gmail.com) ENV SCALA_VERSION 2.10.4 ENV SCALA_TARBALL http://www.scala-lang.org/files/archive/scala-$SCALA_VERSION.deb RUN \ echo "==> Install curl helper tool..."&& \ apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --force-yes curl && \ \ \ \ echo "===> install from Typesafe repo (contains old versions but they have all dependencies we need later on)"&& \ curl -sSL http://apt.typesafe.com/repo-deb-build-0002.deb -o repo-deb.deb && \ dpkg -i repo-deb.deb && \ apt-get update && \ \ \ \ echo "===> install Scala"&& \ DEBIAN_FRONTEND=noninteractive \ apt-get install -y --force-yes libjansi-java && \ curl -sSL $SCALA_TARBALL -o scala.deb && \ dpkg -i scala.deb && \ \ \ \ echo "===> clean up..."&& \ rm -f *.deb && \ apt-get remove -y --auto-remove curl && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* COPY . /home/zyiz/src WORKDIR /home/zyiz/src CMD ["scala", "/home/zyiz/src/index.scala"]
/home/zyiz/docker/scala-docker-app/index.scala
object MainObject{ def main(args:Array[String]){ println("Hello by Scala"); } }
现在,创建这个Scala应用程序的Docker映像。 以下命令用于创建Docker映像。
zyiz@ubuntu:~/docker/scala-docker-app$ sudo docker build -t scala-app .
执行上面代码,输出结果如下 -
zyiz@ubuntu:~/docker/scala-docker-app$ sudo docker build -t scala-app . Sending build context to Docker daemon 3.584kB ....... Removing intermediate container a551438ab33a ...... ---> Running in bc8b748316cc ---> 1d786cf20101 Removing intermediate container bc8b748316cc Successfully built 1d786cf20101 Successfully tagged scala-app:latest zyiz@ubuntu:~/docker/scala-docker-app$
zyiz@ubuntu:~/docker/scala-docker-app$ sudo docker run scala-app
执行上面代码,得到以下结果 -
zyiz@ubuntu:~/docker/scala-docker-app$ sudo docker run scala-app Hello by Scala zyiz@ubuntu:~/docker/scala-docker-app$ sudo docker run scala-app