简体   繁体   English

sbt-native-packager scala播放dockerfile不以默认配​​置运行

[英]sbt-native-packager scala play dockerfile not running with default config

I'm trying to use the sbt-native-packager to produce a Docker image of my Scala play app, I followed the steps described at http://www.scala-sbt.org/sbt-native-packager/formats/docker.html 我正在尝试使用sbt-native-packager生成我的Scala play应用的Docker映像,我按照http://www.scala-sbt.org/sbt-native-packager/formats/docker中描述的步骤进行操作html的

This is my configuration: 这是我的配置:

on my plugins.sbt I added the dependency for sbt native packager: 在我的plugins.sbt中,我添加了sbt本机打包程序的依赖项:

// SBT Native
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.2.1")

on my build.sbt I added the plugins for Universal and Docker: 在我的build.sbt中,我添加了Universal和Docker的插件:

.enablePlugins(PlayScala, JavaAppPackaging)

I also added some extra properties: 我还添加了一些额外的属性:

javaOptions in Universal ++= Seq(
  // JVM memory tuning
  "-J-Xmx1024m",
  "-J-Xms512m",

  // Since play uses separate pidfile we have to provide it with a proper path
  // name of the pid file must be play.pid
  s"-Dpidfile.path=/var/run/${packageName.value}/play.pid",

  // Use separate configuration file for production environment
  s"-Dconfig.file=/usr/share/${packageName.value}/conf/production.conf",

  // Use separate logger configuration file for production environment
  s"-Dlogger.file=/usr/share/${packageName.value}/conf/logback.xml"
)

// exposing the play ports
dockerExposedPorts in Docker := Seq(9000, 9443)

Then I generate the docker image using the plugin and SBT CLI: 然后,我使用插件和SBT CLI生成docker映像:

docker:publishLocal

the dockerfile gets generated at ./target/docker/Dockerfile dockerfile在./target/docker/Dockerfile中生成

when I inspect the file I see: 当我检查文件时,我看到:

FROM openjdk:latest
WORKDIR /opt/docker
ADD opt /opt
RUN ["chown", "-R", "daemon:daemon", "."]
USER daemon
ENTRYPOINT ["bin/root"]
CMD []

which doesn't seem to contain all the necessary steps to run the app, when I use docker build . 当我使用docker build .时,其中似乎没有包含运行应用程序的所有必要步骤docker build . I get : 我得到:

java.nio.file.NoSuchFileException: /var/run/root/play.pid java.nio.file.NoSuchFileException:/var/run/root/play.pid

It seems like the Dockerfile is missing some steps where it should mkdir /var/run/{APP_NAME}/ (* creating folder inside docker container instance) 似乎Dockerfile缺少应在mkdir /var/run/{APP_NAME}/某些步骤(*在Docker容器实例中创建文件夹)

and chown that folder in order for play to create the PID file. 并整理该文件夹以便播放以创建PID文件。

how to fix the above error ? 如何解决以上错误?

What's the error message when starting the docker image and how do you start it? 启动Docker映像时出现什么错误消息,以及如何启动它?

Then there are a couple of notable things. 然后有几件值得注意的事情。

play ships with native-packager 与native-packager一起玩

You shouldn't have to add any plugin, but only configure docker relevant stuff. 您不必添加任何插件,而只需配置与docker相关的内容。 You already linked the correct documentation for the package format ( docker ). 您已经为软件包格式 (docker)链接了正确的文档。

Archetypes Vs Formats 原型与格式

Your configuration won't work without the play plugin. 没有play插件,您的配置将无法正常工作。 Take a look at http://www.scala-sbt.org/sbt-native-packager/archetypes/java_app/index.html which explains how to configure a simple application build. 看看http://www.scala-sbt.org/sbt-native-packager/archetypes/java_app/index.html ,它说明了如何配置简单的应用程序构建。

I'd also recommend to read the format and Archetypes section here: http://www.scala-sbt.org/sbt-native-packager/introduction.html#archetype-plugins 我还建议您在此处阅读格式和原型部分: http : //www.scala-sbt.org/sbt-native-packager/introduction.html#archetype-plugins

Native docker build 本机Docker构建

Native-packager currently generates two docker files, which is confusing and not relevant. Native-packager当前会生成两个docker文件,这令人困惑且不相关。 Sorry for that confusion. 抱歉让您感到困惑。 We plan to remove the redundant docker file. 我们计划删除冗余的docker文件。 Simply go one level deeper and run the docker build command. 只需更深入一层,然后运行docker build命令。

Hope that helps, Muki 希望对您有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM