这是我第一次使用多阶段操作,运行docker-compose up
时出现此错误:
worker_1 |错误:无法访问jarfile worker-jar-with-dependencies.jar
因此似乎找不到文件。
Dockerfile
FROM maven:3.5-jdk-8-alpine AS builder
ADD pom.xml .
RUN mvn dependency:resolve
#RUN /bin/sh -c cd src/
RUN mvn package
FROM openjdk:8-jre-alpine
COPY --from=builder target/worker-jar-with-dependencies.jar .
#RUN java -jar worker-jar-with-dependencies.jar
CMD ["java", "-jar", "worker-jar-with-dependencies.jar"]
以及我的docker-compose.yml外观
version: '3.0'
services:
poll:
build: poll/.
ports:
- "5000:80"
networks:
- poll-tier
redis:
image: "redis"
expose:
- "6379"
networks:
- back-tier
- poll-tier
worker:
build: worker/.
networks:
- back-tier
db:
image: "postgres"
volumes:
- "db-data:/var/lib/postgresql/data"
networks:
- back-tier
- result-tier
environment:
POSTGRES_PASSWORD: popeye
result:
build: result/.
ports:
- "5001:80"
networks:
- result-tier
volumes:
db-data:
networks:
poll-tier: {}
result-tier: {}
back-tier: {}
答案 0 :(得分:1)
您似乎没有在Dockerfile中添加源代码。您的pom仅具有ADD命令,而源中没有一个命令。我想说的是,在“ RUN mvn软件包”之前添加“ COPY src / src”之类的内容。
不确定是否使用springboot,但这是springboot应用程序的多阶段构建示例:
@StateObject var viewModel = PostsViewModel()
您可以在此docker repo中找到以下示例和其他很好的docker-compose示例:https://github.com/docker/awesome-compose