0

I have configured a Firebase properties file as follows -

@Bean
Firestore firestore() throws IOException {
    InputStream serviceAccount = new FileInputStream("my-karwaan-firebase-adminsdk.json");
    GoogleCredentials credentials = GoogleCredentials.fromStream(serviceAccount);

JSON file is present under the resources folder.

Everything works fine on the localhost. But on docker it's throwing while running docker image

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate 
[com.google.cloud.firestore.Firestore]: Factory method 'firestore' threw exception; nested
 exception is java.io.FileNotFoundException: my-karwaan-firebase-adminsdk.json

Docker file content as follows -

# Build Jar File
FROM maven:3.6.3-jdk-8-slim as stage1
WORKDIR /home/app
COPY . /home/app
RUN mvn -f /home/app/pom.xml clean package

# Create an Image
FROM openjdk:8-jdk-alpine
EXPOSE 8080
COPY --from=stage1 /home/app/target/myapp.jar myapp.jar
ENTRYPOINT ["java", "-jar", "myapp.jar"]

I tried to give an absolute path but it's not working on docker.

Directory structure as follows - enter image description here

6
  • The only file you're copying into the result image is the jar file. One of Docker's key features is filesystem isolation: unless you go out of your way to configure it, containers can't see or access files on the host system (or vice versa). Commented May 25, 2020 at 17:07
  • What is the best way here to provide configuration? Commented May 25, 2020 at 17:22
  • What is the location of your dockerfile ?? Commented May 25, 2020 at 17:27
  • @DupinderSingh In project directory Commented May 25, 2020 at 17:29
  • means root location Am i right ? Commented May 25, 2020 at 17:31

1 Answer 1

1

See the basic problem in your dockerfile is

You are setting WORKDIR then while COPY you said COPY in /home/app so if you set WORKDIR then it means Any RUN, CMD, ADD, COPY, or ENTRYPOINT command will be executed in the specified working directory.

enter image description here

So to avoid the confusions try as following

# Build Jar File
FROM maven:3.6.3-jdk-8-slim as stage1
WORKDIR /home/app
#COPY FROM PROJECT ROOT DIR TO WORKING ROOT DIR i.e: /home/app 
COPY . .
RUN mvn -f /home/app/pom.xml clean package

# Create an Image
FROM openjdk:8-jdk-alpine
EXPOSE 8080
COPY --from=stage1 /home/app/target/myapp.jar myapp.jar
ENTRYPOINT ["java", "-jar", "myapp.jar"]

Try this :)

PS: Once you start the container please do exec and check is all the project details are at right directory or not and mvn build is building jar with correct name or not

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.