Unable to run two Spring boot services with docker compose. Error: Unable to access jarfile target/gs-rest-service-0.1.0.jar

孤人 提交于 2019-12-11 18:53:49

问题


I had a similar issue before and was recommended to create a new question, again unable to run two services , but this time both services are Spring Boot.

 The project structure:/
    - docker-compose.yml
    - Dockerfile
    - pom.xml
    - src/
    - ... other spring boot web service folders and files
    - rest-bookstore/ (the 2nd webservice)
      -Dockerfile
      -rest
        -src
        -target
          -gs-rest-service-0.1.0.jar
    -... other files and folders

The Dockerfile of the first spring boot service(this one is the main one and launches normally):

FROM maven:3.6-jdk-8 AS build  

WORKDIR /code

COPY src /code/app/src
COPY pom.xml /code/app
RUN mvn -f /code/app/pom.xml clean install

FROM openjdk:8
COPY --from=build /code/app/target/SpringWebServiceToDoList-0.0.1-SNAPSHOT.jar SpringWebServiceToDoList-0.0.1-SNAPSHOT.jar
EXPOSE 5000
CMD ["java","-jar","SpringWebServiceToDoList-0.0.1-SNAPSHOT.jar"]

The dockerfile of the 2nd web service:

FROM maven:3.6.0-jdk-8-alpine
COPY rest /rest
WORKDIR /rest
RUN mvn clean package
CMD java -jar target/gs-rest-service-0.1.0.jar --server.port=5000

And the docker-compose.yml

version: '3'

services:
  springboot-docker-compose-app-container:
    build: .
    ports:
      - "80:5000"
    depends_on:
    - friendservice
    volumes:
    - .:/code
    networks:
    - mynet
  friendservice:
    build: ./rest-bookstore
    volumes:
    - ./rest-bookstore:/rest
    ports:
    - 5000:5001
    networks:
    - mynet

networks:
    mynet:

I get Error: Unable to access jarfile target/gs-rest-service-0.1.0.jar And I don't know why since in the second dockerfile copies the whole rest directory. I use the command "docker-compose up --build -d".

Thank you for the help.

Reference to the similar issue: Unable to run two docker containers with docker-compose. I get the error: "python: can't open file 'app.py': [Errno 2] No such file or directory"

来源:https://stackoverflow.com/questions/55733887/unable-to-run-two-spring-boot-services-with-docker-compose-error-unable-to-acc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!