Reputation: 1635
I am trying to build a docker image for a java app. I have done the following in the dockerfile :
FROM java:8
RUN javac HelloDocker.java
CMD ["java","HelloDocker"]
When I am trying to build the image it is throwing the following exception :javac: file not found: HelloDocker.java
The HelloDocker.java file and Dockerfile is in the same directory.
Also, when I tried to compile the java file separately (via javac HelloDocker.java), it did not throw any error.
Upvotes: 2
Views: 5312
Reputation: 334
Assuming this is the complete Dockerfile, you need to have a file named HelloDocker.java in your docker image's file system, before you can compile the file using "RUN javac HelloDocker.java" . You may copy the file from your host's file system to you docker image using docker COPY/ADD command.
Upvotes: 2
Reputation: 146510
You are using a deprecated image. You should be using openjdk
image. See the below
https://hub.docker.com/_/openjdk/
Also you need javac
so you should be using the one with jdk
tag and not the jre
tag.
So try openjdk:8-jdk
Edit-1
Also you need to copy the files inside your Dockerfile. When you use docker build .
, then the current directory files as available to you as context but they are not inside image
FROM java:8
WORKDIR /app
COPY HelloDocker.java .
RUN javac HelloDocker.java
CMD ["java","HelloDocker"]
Upvotes: 2