Fryder
Fryder

Reputation: 423

Docker compose build relative path

creditcard-monk:
 build:
  context: ./creditcard
  dockerfile: Dockerfile
  args:
    JAR_FILE: target/creditcard-1.0.0.jar

Docker compose version 3.0. The jar_file argument is used to copy the jar-file to spring-boot jar under docker container

I get the error failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder347176151/target/creditcard-1.0.0.jar: no such file or directory

i thought the mentioning of context ,will read jar from target folder .but it seems docker-compose is not reading the file from context specified

Please help. Note:- the docker file is simple, built from alpine-java-8 and a copy command to copy jar to container to start spring boot app

Upvotes: 5

Views: 4429

Answers (2)

Fryder
Fryder

Reputation: 423

version: "3.1"
services:
    creditcard-monk:
     build:
      context: ./
      dockerfile: Dockerfile
      args:
        JAR_FILE: target/creditcard-1.0.0.jar

or

docker build --build-arg JAR_FILE=target/creditcard-1.0.0.jar

both commands worked now. But the second command worked in most cases and never failed.

As the docker is already running inside the folder

Upvotes: 2

REA_ANDREW
REA_ANDREW

Reputation: 10764

Your current code assumes the following path exists:

./creditcard/target/creditcard-1.0.0.jar

The JAR_FILE path will be inside the path you specified for context. Double check what the path should be and update your context and JAR_FILE argument accordingly.

Upvotes: 0

Related Questions