为 Spring Cloud 配置服务器创建 docker 文件

我正在尝试为我的配置服务器构建 docker 映像。这些是我遵循的步骤:

  • 打开https://start.spring.io/ 并添加 config-server 作为依赖项。然后下载该项目。

  • 添加@EnableConfigServer注释于 demo\src\main\java\com\example\demo\DemoApplication.java

  • 添加以下代码demo\src\main\resources\application.properties

server.port=8888  spring.cloud.config.server.git.uri=https://github.com/mygitusername/configserverdata.git

当我mvn spring-boot:run在本地使用命令启动配置服务器时,它工作正常。

现在我想为我的配置服务器创建 docker 映像。

FROM maven:alpine

MAINTAINER hyness <hyness@freshlegacycode.org>


EXPOSE 8888

COPY . /Demo/

WORKDIR /Demo/

RUN mvn package

VOLUME /config

WORKDIR /

ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar",\

            "/Demo/target/Demo.jar",\

            "--server.port=8888",\

            "--spring.config.name=application"]

当我执行时docker build -t spring-cloud-config-server .它说 BUILD Failure with this Reason


您指定的目标需要一个项目来执行,但此目录(/demo)中没有 POM。请验证您从正确的目录调用 Maven。


请帮助我为我的配置服务器创建正确的 docker 文件。


mvn spring-boot:run这可能是一个愚蠢的问题,但我也需要在 Dockerfile 中指定。


我刚刚开始学习docker。


饮歌长啸
浏览 163回答 1
1回答

紫衣仙女

我刚刚构建了该应用程序,它与这个 Dockerfile 和 dirs 布局一起工作得很好(看看“COPY ./demo /demo/”):FROM maven:alpineMAINTAINER hyness <hyness@freshlegacycode.org>EXPOSE 8888COPY ./demo /demo/WORKDIR /demo/RUN mvn packageVOLUME /configWORKDIR /ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar",\&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "/demo/target/demo.jar",\&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "--server.port=8888",\&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "--spring.config.name=application"]$ tree.├── demo│&nbsp; &nbsp;├── pom.xml│&nbsp; &nbsp;└── src│&nbsp; &nbsp; &nbsp; &nbsp;└── main│&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;├── java│&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;│&nbsp; &nbsp;└── com│&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;│&nbsp; &nbsp; &nbsp; &nbsp;└── example│&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;│&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;└── demo│&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;│&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;└── DemoApplication.java│&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;└── resources│&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;└── application.properties└── Dockerfile
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java