1

When I run docker-compose up I am getting following ERROR: cannot locate specified Dockerfile:Dockerfile here is my docker-compose file:

      version: "3"
services:
    player-docker:
        build: ./src/main/java/spring/multiple/mongo/project/player
        restart: always
        ports:
            - 8080:8080
        depends_on:
            - db
    game-docker:
        build: ./src/main/java/spring/multiple/mongo/project/game
        restart: always
        ports:
            - 8080:8080
        depends_on:
            - db
    score-docker:
        build: ./src/main/java/spring/multiple/mongo/project/score
        restart: always
        ports:
            - 8080:8080
        depends_on:
            - db 
    db:
        image: mongo
        volumes:
            - mongodata:/data/db
        ports:
            - "27017:27017"
        restart: always
volumes:
    mongodata:

and I have three Dockerfiles each for player service, game service and score service in different locations. This is my Dockerfile:

    FROM openjdk:8
COPY target/demo-0.0.1-SNAPSHOT.jar score.jar
EXPOSE 8080
ENTRYPOINT ["java","-Dspring.data.mongodb.uri=mongodb://db:27017/","-jar","-Djava.rmi.server.hostname=0.0.0.0", "score.jar"]

the error

saharsa
  • 467
  • 1
  • 7
  • 24
  • you would need to show your directory structure. – Michał Krzywański Jun 10 '20 at 09:49
  • 1
    You told all three services to `build: .`, the current directory. If the Dockerfiles are in different directories you need to change those `build:` lines to point there. – David Maze Jun 10 '20 at 10:04
  • @DavidMaze but when I changed build: . to build: "the location of my dockerfile" I had an error after using docker-compose up. the error is: "Service score-docker failed to build: COPY failed:......: no such file or directory – saharsa Jun 10 '20 at 10:50
  • As suggest by @DavidMaze, you should change the `build: .` to proper folder of Dockerfile for each 3 services. And revise your Dockerfile's `COPY` instruction, you can use relative path like `COPY ../target/demo-0.0.1-SNAPSHOT.jar score.jar` – Dai Jun 10 '20 at 14:38
  • (Reading through questions like [How to include files outside of Docker's build context?](https://stackoverflow.com/questions/27068596/how-to-include-files-outside-of-dockers-build-context) can be informative, if the images need to share files from a common directory.) – David Maze Jun 10 '20 at 15:05
  • @Dai I did all these things for my services. but nothing changed and when I use docker-compose up the error is the same as before. "Service score-docker failed to build: COPY failed:......: no such file or directory I do not know why – saharsa Jun 11 '20 at 08:16
  • I updated my question and error that i had got. @Dai – saharsa Jun 11 '20 at 08:25

1 Answers1

2

I think you should revise your docker-compose file similar to the following:

    score-docker:
        build:
            context: ./
            dockerfile: ./src/main/java/spring/multiple/mongo/project/score/Dockerfile

The point is, you need include your target/demo-0.0.1-SNAPSHOT.jar score.jar into the docker build context. Otherwise, the Dockerfile COPY instruction will not able to find the file. (I suppose you have the targer folder sibling as src folder).

Dai
  • 397
  • 4
  • 14