我正在尝试在Play 2.2项目上构建Docker镜像。我在Ubuntu Linux上使用Docker 1.2.0版。
Build.scala中我的Docker特定设置如下所示:
dockerBaseImage in Docker := "dockerfile/java:7"
maintainer in Docker := "My name"
dockerExposedPorts in Docker := Seq(9000, 9443)
dockerExposedVolumes in Docker := Seq("/opt/docker/logs")
生成的Dockerfile:
FROM dockerfile/java:latest
MAINTAINER
ADD files /
WORKDIR /opt/docker
RUN ["chown", "-R", "daemon", "."]
USER daemon
ENTRYPOINT ["bin/device-guides"]
CMD []
输出看起来像dockerBaseImage被忽略,默认
(dockerfile/java:latest) is not handled correctly:
[project] $ docker:publishLocal
[info] Wrote /..../project.pom
[info] Step 0 : FROM dockerfile/java:latest
[info] ---> bf7307ff060a
[info] Step 1 : MAINTAINER
[error] 2014/10/07 11:30:12 Invalid Dockerfile format
[trace] Stack trace suppressed: run last docker:publishLocal for the full output.
[error] (docker:publishLocal) Nonzero exit value: 1
[error] Total time: 2 s, completed Oct 7, 2014 11:30:12 AM
[project] $ run last docker:publishLocal
java.lang.RuntimeException: Invalid port argument: last
at scala.sys.package$.error(package.scala:27)
at play.PlayRun$class.play$PlayRun$$parsePort(PlayRun.scala:52)
at play.PlayRun$$anonfun$play$PlayRun$$filterArgs$2.apply(PlayRun.scala:69)
at play.PlayRun$$anonfun$play$PlayRun$$filterArgs$2.apply(PlayRun.scala:69)
at scala.Option.map(Option.scala:145)
at play.PlayRun$class.play$PlayRun$$filterArgs(PlayRun.scala:69)
at play.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$1.apply(PlayRun.scala:97)
at play.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$1.apply(PlayRun.scala:91)
at scala.Function7$$anonfun$tupled$1.apply(Function7.scala:35)
at scala.Function7$$anonfun$tupled$1.apply(Function7.scala:34)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) Invalid port argument: last
[error] Total time: 0 s, completed Oct 7, 2014 11:30:16 AM
要使这项工作需要做些什么?
我可以从命令行使用Docker构建映像:
docker build --force-rm -t device-guides:1.0-SNAPSHOT .
答案 0 :(得分:2)
打包/发布设置是按项目设置,而不是按构建设置。
您使用的是Build.scala
样式版本,其格式如下:
object ApplicationBuild extends Build {
val main = play.Project(appName, appVersion, libraryDependencies).settings(
...
)
}
这些设置应该应用于此main
项目。这意味着您可以在项目上调用settings()
方法,并根据需要传递适当的设置来设置包装。
在这种情况下:
object ApplicationBuild extends Build {
val main = play.Project(appName, appVersion, libraryDependencies).settings(
dockerBaseImage in Docker := "dockerfile/java:7",
maintainer in Docker := "My name",
dockerExposedPorts in Docker := Seq(9000, 9443),
dockerExposedVolumes in Docker := Seq("/opt/docker/logs")
)
}
要在多个项目中重复使用类似设置,您可以创建类型为Seq[sbt.Setting]
的val,也可以扩展sbt.Project
以提供常用设置。有关如何执行此操作的示例(例如规则#4),请参阅http://jsuereth.com/scala/2013/06/11/effective-sbt.html。
如果习惯使用build.sbt
- 类型构建,则此设置放置不一定清楚,因为在该文件中,评估为SBT设置(或设置序列)的行会自动附加到根项目的设置。
答案 1 :(得分:1)
这是你执行的错误命令。我没有第一次看到它。
run last docker:publishLocal
删除最后一次运行
docker:publishLocal
现在,您可以按预期方式构建docker镜像