Docker на Windows 10. Ресурсы контроллера REST не получены из контейнера - PullRequest
0 голосов
/ 07 февраля 2020

Я создал службу REST при загрузке Spring:

Основной класс:

@SpringBootApplication
public class HelloFessApplication {
    public static void main(String[] args) {
        SpringApplication.run(HelloFessApplication.class, args);
        System.out.println("Hello, Fess");
    }
}

Контроллер REST:

@RestController
@RequestMapping("/greeting")
public class GreetingController {
    @GetMapping
    public String greeting() {
        return "Hello, Fess, from controller!";
    }
}

application.yml

server:
    port: 8070
    servlet:
        context-path: /fess-greeter

Dockerfile:

FROM java:8-jdk-alpine
COPY target/hello-fess.war .
EXPOSE 8070
ENTRYPOINT ["java", "-jar", "hello-fess.war"]

В Docker Панель инструментов Я использую следующие команды:

- cd to directory with project (/d/Programming/Java/hello-fess)
- docker build -t fess .

как результат:

Successfully built a98fd0a65ca0
Successfully tagged fess:latest

следующий

- docker run -it -p 8000:8070 a98fd0a65ca0 

в результате:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.4.RELEASE)

2020-02-07 16:14:27.887  INFO 1 --- [           main] c.f.hellofess.HelloFessApplication       : Starting HelloFessApplication v0.0.1-SNAPSHOT on f03f7c4f8fc6 with PID 1 (/hello-fess.war started by root in /)
2020-02-07 16:14:27.892  INFO 1 --- [           main] c.f.hellofess.HelloFessApplication       : No active profile set, falling back to default profiles: default
2020-02-07 16:14:29.396  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8070 (http)
2020-02-07 16:14:29.415  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-02-07 16:14:29.416  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.30]
2020-02-07 16:14:30.499  INFO 1 --- [           main] org.apache.jasper.servlet.TldScanner     : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2020-02-07 16:14:30.625  INFO 1 --- [           main] o.a.c.c.C.[.[localhost].[/fess-greeter]  : Initializing Spring embedded WebApplicationContext
2020-02-07 16:14:30.627  INFO 1 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2651 ms
2020-02-07 16:14:31.392  INFO 1 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-02-07 16:14:31.636  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8070 (http) with context path '/fess-greeter'
2020-02-07 16:14:31.641  INFO 1 --- [           main] c.f.hellofess.HelloFessApplication       : Started HelloFessApplication in 4.382 seconds (JVM running for 4.954)
Hello, Fess

Поэтому, когда я пытаюсь открыть URL-адрес http://localhost: 8000 / Fess-Greeter / приветствие Я вижу:

This site can’t be reached. localhost refused to connect.

Я делал одни и те же шаги в разных уроках, когда на этих шагах люди получали нормальные ответы по ссылкам из контейнера.

Итак, что мне нужно сделать для запуска контейнера с моим приложением Spring и получения ресурса из контроллера REST внутри Docker Toolbox? Спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...