Pavel
Pavel

Reputation: 2101

Set src file path into Dockerfile

After compilation .jar file in:

/var/lib/jenkins/workspace/PROD__Backend-Build-Deploy/target/laplacelab-0.0.1-SNAPSHOT.jar

But old Dockerfile was run just from a folder with .jar and Dockerfile.

FROM adoptopenjdk/openjdk11

VOLUME /tmp
ADD laplacelab-0.0.1-SNAPSHOT.jar laplacelab-0.0.1-SNAPSHOT.jar
RUN sh -c 'touch /laplacelab-0.0.1-SNAPSHOT.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/laplacelab-0.0.1-SNAPSHOT.jar"]

Where I should change the path for new dir? Only in ENTRYPOINT line or ADD need to change too? What should it be like to be for the new structure?

Upvotes: 0

Views: 655

Answers (1)

Andrew
Andrew

Reputation: 143

Docker can't access files outside of the Docker build context, so you will need to either move the file or specify the context in your build command, e.g.:

docker build -t foo:latest /var/lib/jenkins/workspace/PROD__Backend-Build-Deploy/target/

If you do not have your Dockerfile in the same directory as your build context, you will need to specify its location using -f, like this:

docker build -t foo:latest -f ./Dockerfile /var/lib/jenkins/workspace/PROD__Backend-Build-Deploy/target/

In Compose it can look something like this:

build:
  context: /var/lib/jenkins/workspace/PROD__Backend-Build-Deploy/target/
  dockerfile: ./Dockerfile

Upvotes: 1

Related Questions