Deploy Spring WAR on Tomcat-based docker

I went through Spring Creating a RESTful Web Service tutorial and created a dummy webapp (with instructions "Build with Maven"), I build and package the WAR. Then I run it with this command:

java -jar ./target/Dummy-1.0-SNAPSHOT.war

I see a dummy JSON endpoint at http: // localhost: 8080 / greeting / .

Now I want to containerize the application with Docker, so I can test it again without having to install Tomcat in the system space. This is created by Dockerfile:

FROM tomcat:7-jre8-alpine

# copy the WAR bundle to tomcat
COPY /target/Dummy-1.0-SNAPSHOT.war /usr/local/tomcat/webapps/app.war

# command to run
CMD ["catalina.sh", "run"]

I am creating and running docker binding to http: // localhost: 8080 . I see the Tomcat welcome page on " http: // localhost: 8080 ". But I could not see my application with any of them:

How do I track a problem? What could be the problem?

Update 1: Screenshot of the Tomcat Admin Interface

Tomcat admin

+4
source share
1 answer

The file Application.javain the example is as follows:

package hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

SpringBoot, Tomcat. , :

  • redefine Application SpringBootServletInitializer Spring -;
  • configure:

    package hello;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.builder.SpringApplicationBuilder;
    import org.springframework.boot.web.support.SpringBootServletInitializer;    
    
    @SpringBootApplication
    public class Application extends SpringBootServletInitializer {
    
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(Application.class);
        }
    
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    
    }
    

pom.xml ( ).

docker , : http://localhost:8080/app/greeting/

+1

Source: https://habr.com/ru/post/1680772/


All Articles