Docker Scala应用程序示例
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"]
- 创建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$
- 运行Scala Docker映像
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
关注微信小程序
扫描二维码
程序员编程王