Docker允許我們執行Scala應用程式。 在這裡,我們將演示如何建立一個Scala檔案,並使用docker進行執行,此範例包括以下步驟。
$ mkdir - /home/yiibai/docker/scala-docker-app
$ cd /home/yiibai/docker/scala-docker-app
Dockerfile
的 Dockerfile 檔案FROM williamyeh/java7
MAINTAINER Hema ([email protected])
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");
}
}
現在,建立這個Scala應用程式的Docker映像。 以下命令用於建立Docker映像。
yiibai@ubuntu:~/docker/scala-docker-app$ sudo docker build -t scala-app .
執行上面程式碼,輸出結果如下 -
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
執行上面程式碼,得到以下結果 -
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