Docker允許我們執(zhí)行Scala應(yīng)用程序。 在這里,我們將演示如何創(chuàng)建一個Scala文件,并使用docker進(jìn)行執(zhí)行,此示例包括以下步驟。
$ mkdir - /home/yiibai/docker/scala-docker-app
$ cd /home/yiibai/docker/scala-docker-app
Dockerfile
的 Dockerfile 文件FROM williamyeh/java7
MAINTAINER Hema (yiibai.com@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/yiibai/src
WORKDIR /home/yiibai/src
CMD ["scala", "/home/yiibai/src/index.scala"]
/home/yiibai/docker/scala-docker-app/index.scala
object MainObject{
def main(args:Array[String]){
println("Hello by Scala");
}
}
現(xiàn)在,創(chuàng)建這個Scala應(yīng)用程序的Docker映像。 以下命令用于創(chuàng)建Docker映像。
yiibai@ubuntu:~/docker/scala-docker-app$ sudo docker build -t scala-app .
執(zhí)行上面代碼,輸出結(jié)果如下 -
yiibai@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
yiibai@ubuntu:~/docker/scala-docker-app$
yiibai@ubuntu:~/docker/scala-docker-app$ sudo docker run scala-app
執(zhí)行上面代碼,得到以下結(jié)果 -
yiibai@ubuntu:~/docker/scala-docker-app$ sudo docker run scala-app
Hello by Scala
yiibai@ubuntu:~/docker/scala-docker-app$ sudo docker run scala-app