Ardit Meti Ardit Meti - 8 months ago 52
Java Question

Docker file for java project

I have a project, which uses Mave+spring+hibernate+mysql database and I want to create a docker image of this project. I did it using these 2 commands

$ mvn package docker:build
$ docker push name/name

I can create the image, but I currently have no main function so when I try to run the image It gives error no main function found. I know it should have one, but I don't know how to make that. I currently run the project by right-click->Run as->Run on server. I'm using spring tool suite. How can I create a main function that does that same thing? So when I try to run my docker image it will be ok?


FROM java:7
ADD name-ws.jar app.jar
RUN sh -c 'touch /app.jar'
ENTRYPOINT ["java","","-jar","/app.jar"]


The docker file you are using is meant to run a spring boot application, a way of deploying spring applications that include an embedded web server in a jar.

Including the maven artifacts for spring boot might be your shortest path forward. It'll include a class that simply looks something like this:

public class RestApplication  {

  public static void main(final String... args) throws Exception {
    ApplicationContext ctx  =, args);

If that's not what you want to do, then you can use a docker image that executes your application in tomcat, jetty, or whatever. There are plenty out there, just choose one.