嘿大家我在使用本地打包程序创建Scalatra Web应用程序的docker镜像时遇到问题。我的build.sbt文件的相关部分在这里:
enablePlugins(JettyPlugin)
enablePlugins(JavaAppPackaging)
enablePlugins(DockerPlugin)
// for Docker, the "." location where it is looking for files is in target/docker/stage. For the COPY command to work,
// the sbt Docker packager has to know this file resides in ../../scala-2.11 so include this mapping
//mappings in Docker += file("../../scala-2.11/direct2-batch-match_2.11-0.1.0-SNAPSHOT.war") -> "direct2-batch-match_2.11-0.1.0-SNAPSHOT.war"
dockerCommands := Seq(Cmd("FROM","tomcat:8.0.20-jre8"), Cmd("LABEL", """vendor="Dun & Bradstreet" """), Cmd("LABEL", """version="0.0" """), Cmd("EXPOSE", "8080"), Cmd("COPY","direct2-batch-match_2.11-0.1.0-SNAPSHOT.war","webapps/d2bm.war"))
正如您所看到的,我在Docker中注释掉了映射。原因是如果我将其保留,它会在target / docker / stage中创建一个与我的war文件同名的空目录(在本例中为direct2-batch-match_2.11-0.1.0-SNAPSHOT.war) 。这允许Dockerfile在docker构建中正常工作,但war文件的内容不包含在构建中。
我在Mac OS X上运行,我想知道这是否是插件试图创建指向所需文件的链接的错误,也许Linux的链接命令在Mac OS X Sierra上产生了错误的结果。
我需要以不同方式进行映射吗?有没有其他人遇到这个?我在sbt中运行docker:publishLocal时创建了空目录,我使用的是插件版本1.2.0-M9。
在sbt:
中运行docker:publishLocal的结果docker:publishLocal
[info] Updating {file:/Users/cardm/projects/direct2-batch-match/}direct2-batch-match...
[info] Wrote /Users/cardm/projects/direct2-batch-match/target/scala-2.11/direct2-batch-match_2.11-0.1.0-SNAPSHOT.pom
[info] Resolving org.scalatra.scalate#scalate-precompiler_2.11;1.8.0.1 ...
[info] Done updating.
[info] Compiling Templates in Template Directory: /Users/cardm/projects/direct2-batch-match/src/main/webapp/WEB-INF/templates
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[warn] You have no main class in your project. No start script will be generated.
[warn] You have no main class in your project. No start script will be generated.
[info] Sending build context to Docker daemon 74.45 MB
[info] Step 1/5 : FROM tomcat:8.0.20-jre8
[info] ---> e88a065848be
[info] Step 2/5 : LABEL vendor "Dun & Bradstreet"
[info] ---> Using cache
[info] ---> de03acb09377
[info] Step 3/5 : LABEL version "0.0"
[info] ---> Using cache
[info] ---> f4f3e4accacb
[info] Step 4/5 : EXPOSE 8080
[info] ---> Using cache
[info] ---> f971b388dc2c
[info] Step 5/5 : COPY direct2-batch-match_2.11-0.1.0-SNAPSHOT.war webapps/d2bm.war
[info] ---> 60a95c386e23
[info] Removing intermediate container cf15079616cd
[info] Successfully built 60a95c386e23
[info] Built image DockerAlias(None,None,direct2-batch-match,Some(0.1.0-SNAPSHOT))
[success] Total time: 4 s, completed Apr 28, 2017 6:35:09 PM
target / docker / stage的内容:
Mike-Cards-MacBook-Pro:direct2-batch-match cardm$ ls -la target/docker/stage/
total 8
drwxr-xr-x 5 cardm staff 170 Apr 28 18:35 .
drwxr-xr-x 4 cardm staff 136 Apr 28 18:35 ..
-rw-r--r-- 1 cardm staff 156 Apr 28 18:35 Dockerfile
drwxr-xr-x 2 cardm staff 68 Dec 31 1969 direct2-batch-match_2.11-0.1.0-SNAPSHOT.war
drwxr-xr-x 3 cardm staff 102 Apr 28 18:35 opt
正如你所看到的那样是错误的,将空目录放在那里而不是文件是没用的,这就是为什么我认为这应该是一个链接。在我的set文件中,如果我使用“Universal中的映射”而不是它产生相同的结果,一个带有war文件名称的空目录。
答案 0 :(得分:1)
嘿大家发现问题在于我的sbt文件是如何设置的,特别是Docker中的#34;映射"部分。我项目的正确设置如下:
mappings in Docker += file("target/scala-2.11/direct2-batch-match_2.11-0.1.0-SNAPSHOT.war") -> "direct2-batch-match_2.11-0.1.0-SNAPSHOT.war"
这里的诀窍是"来源"文件( - >的左侧)相对于PROJECT ROOT文件夹,目标文件( - >的右侧)相对于docker staging目录,该目录位于PROJECT ROOT / target / docker / stage中。在我的原始设置中,我假设两个文件路径都相对于Docker临时目录,并且在调试sbt-native-packager插件时,我发现这两个路径相对于不同的根位置。
我真的认为应该更新Docker的sbt-native-packager文档以明确这一点。