0

I reference an HTML file in my code, and access it with:

Path filePath1 = Path.of("./email.html");

When I run the project locally, the project works fine, and the file loads normally. However, when running the project in a Docker container, I get the following error:

java.nio.file.NoSuchFileException: ./email.html

Here is my Docker file for reference

FROM openjdk:11.0-jdk-slim as builder

VOLUME /tmp
COPY . .
RUN apt-get update && apt-get install -y dos2unix
RUN dos2unix gradlew
RUN ./gradlew build

# Phase 2 - Build container with runtime only to use .jar file within
FROM openjdk:11.0-jre-slim
WORKDIR /app
# Copy .jar file (aka, builder)
COPY --from=builder build/libs/*.jar app.jar
ENTRYPOINT ["java", "-Xmx300m",  "-Xss512k", "-jar", "app.jar"]
EXPOSE 8080

Thank you for the answers. So this is a Java project, so there is no index.html to add. I tried changing the work directory to /src, but it is still not picking it up

2
  • Is your file located at /app/email.html? You set the WORKDIR to /app in your Dockerfile, so any relative file references in your code should be relative to /app. Commented May 2, 2022 at 4:30
  • the file is in the root directory. I tried putting it in the src folder, and also just commenting out the WORKDIR line (so it stays at the root level), but neither worked Commented May 3, 2022 at 3:52

2 Answers 2

3

Docker has no access to the filesystem fromm the host OS. You need to put it in there as well:

COPY ./index.html index.html
Sign up to request clarification or add additional context in comments.

Comments

0

There's a couple of options:

  1. Copy the index.html in the docker image (solution by ~dominik-lovetinsky)
  2. Mount the directory with your index.html file as a volume in your docker instance.
  3. Include the index.html as a resource in your app.jar, and access it as a classpath resource.

The last option: including resources as classpath resource, is the normal way webapps work, but I'm not sure if it works for you.

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.