I realize that this question may already have been asked, but in my research I can't find an answer. I'm probably making a simple mistake.
I would like to run a Java class locally with Docker, inside a container. Below is my Dockerfile:
Dockerfile
FROM maven:3.5.2-jdk-8
COPY src /src
RUN javac src/java/com/Main.java
CMD java src/java/com/Main
I then run these commands in order:
docker build -t my_image_6_26_19:latest .
docker run -it my_image_6_26_19:latest
The build
command runs fine, but the run
command throws the following error:
Error: Could not find or load main class src.java.com.Main
I have reviewed the following questions on SO, but no answers seem to work (or maybe I didn't catch the solution):
- Buildning docker image from Dockerfile with maven - Error: "Could not find or load main class"
- DockerFile to run a java program
- Docker Error: Could not find or load Main class Main.Main
When I build the container, through some debugging (RUN ls /src/java/com
) I can see that a file Main.class
is being created. I'm not sure why that file can't be found. Additionally, I have tried changing the last line of my Dockerfile to CMD java src/java/com/Main.class
, but no luck.