【发布时间】:2020-06-07 11:39:07
【问题描述】:
弹簧靴。我通过 Gradle 构建和运行项目。
gradlew bootRun
这是成功的构建和运行。 不错。
现在我想通过 Docker compose 构建和运行。 这是我的 Dockerfile:
FROM openjdk:8
FROM gradle
RUN gradle wrapper
RUN ./gradlew bootRun
ADD build/libs/eshop-1.0.0.jar eshop-1.0.0.jar
ENTRYPOINT ["java", "-jar", "eshop-1.0.0.jar"]
在 docker-compose.yml 中
version: "3"
services:
server:
build: .
command: java -jar build/libs/eshop-1.0.0.jar
ports:
- 8090:8090
现在在 Docker 的工具中运行命令如下:
$ docker-compose build
Building server
Step 1/6 : FROM openjdk:8
---> 8c6851b1fc09
Step 2/6 : FROM gradle
---> 1fcd09a6bb3b
Step 3/6 : RUN gradle wrapper
---> Using cache
---> acf242fa68db
Step 4/6 : RUN ./gradlew bootRun
---> Running in 8c7c62db19f9
Downloading https://services.gradle.org/distributions/gradle-6.2-bin.zip
.........10%.........20%.........30%..........40%.........50%.........60%..........70%.........80%.........90%..........100%
Welcome to Gradle 6.2!
Here are the highlights of this release:
- Dependency checksum and signature verification
- Documentation links in deprecation messages
- Shareable read-only dependency cache
For more details see https://docs.gradle.org/6.2/release-notes.html
Starting a Gradle Daemon (subsequent builds will be faster)
FAILURE: Build failed with an exception.
* What went wrong:
Task 'bootRun' not found in root project 'gradle'.
* Try:
Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1m 10s
ERROR: Service 'server' failed to build: The command '/bin/sh -c ./gradlew bootRun' returned a non-zero code: 1
那么为什么我会出错?
【问题讨论】:
-
为了让 bootRun 工作,你的应用程序的源代码必须在容器中。我在你的 Dockerfile 中看不到任何添加它的东西。在容器之外构建您的应用程序,然后将其 fat jar 或其类和依赖项添加到容器中会更传统。你在容器内执行 bootRun 的原因是什么?
-
@AndyWilkinson 我添加了我的答案
标签: spring-boot docker-compose