Search code examples
dockerdocker-composedockerfiledocker-for-windows

Docker-compose Error cannot locate specified Dockerfile: Dockerfile


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


Solution

  • 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).