无法访问在Docker容器中运行的Maven Spring Boot应用程序

时间:2020-01-17 12:31:15

标签: spring-boot docker dockerfile portforwarding docker-container

我已经从maven spring boot应用程序创建了一个docker文件,并创建了一个docker映像并将其推送到我的docker注册表中。

FROM openjdk:8
ADD target/spring-boot-lazy-init-example-0.0.1-SNAPSHOT.jar spring-boot-lazy-init-example-0.0.1-SNAPSHOT.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "spring-boot-lazy-init-example-0.0.1-SNAPSHOT.jar"]

这是我在docker文件中编写并创建docker映像的内容。我已经更改了标签并将其推送到我的Docker中心存储库中,该库将用于Kubernetes集群中的部署目的,但在此之前,我已经将此Docker映像用于测试目的。我已使用此docker映像运行容器,并且由于应用程序默认在8080端口上运行,因此我也完成了端口转发。

ubuntu@dockerimage-vm:~/spring-boot-lazy-init-example$ sudo docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
96963/spring-boot-new      v1                  1e4a8aab28f8        3 days ago          526MB
96963/docker-spring-boot   v1                  2f2a3b1c23e8        8 days ago          526MB
docker-spring-boot-new     latest              2f2a3b1c23e8        8 days ago          526MB
openjdk                    8                   f8146facf376        2 weeks ago         488MB

ubuntu@dockerimage-vm:~$ sudo docker run -it 96963/spring-boot-new:v1 -p 8085:8080

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

2020-01-17 11:38:21.417  INFO 1 --- [           main] t.l.SpringBootLazyInitExampleApplication : Starting SpringBootLazyInitExampleApplication v0.0.1-SNAPSHOT on 03ab2d24c370 with PID 1 (/spring-boot-lazy-init-example-0.0.1-SNAPSHOT.jar started by root in /)
2020-01-17 11:38:21.426  INFO 1 --- [           main] t.l.SpringBootLazyInitExampleApplication : No active profile set, falling back to default profiles: default
2020-01-17 11:38:23.355  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2020-01-17 11:38:23.451  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 67ms. Found 0 repository interfaces.
2020-01-17 11:38:24.391  INFO 1 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$cf2fe8c5] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-01-17 11:38:25.625  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-01-17 11:38:26.191  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-01-17 11:38:26.192  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.16]
2020-01-17 11:38:26.258  INFO 1 --- [           main] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
2020-01-17 11:38:26.486  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-01-17 11:38:26.489  INFO 1 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 4929 ms
2020-01-17 11:38:27.532  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2020-01-17 11:38:28.182  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2020-01-17 11:38:28.398  INFO 1 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2020-01-17 11:38:28.627  INFO 1 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.4.0.Final}
2020-01-17 11:38:28.640  INFO 1 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2020-01-17 11:38:29.171  INFO 1 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-01-17 11:38:29.438  INFO 1 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2020-01-17 11:38:30.312  INFO 1 --- [           main] o.h.t.schema.internal.SchemaCreatorImpl  : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@1b11171f'
2020-01-17 11:38:30.337  INFO 1 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-01-17 11:38:30.339  INFO 1 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-01-17 11:38:30.694  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2020-01-17 11:38:30.701  INFO 1 --- [           main] t.l.SpringBootLazyInitExampleApplication : Started SpringBootLazyInitExampleApplication in 10.338 seconds (JVM running for 11.976)
2020-01-17 12:08:38.990  WARN 1 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Thread starvation or clock leap detected (housekeeper delta=28m10s615ms885µs724ns)

我也尝试从本地计算机运行应用程序,并且能够访问URL enter image description here

enter image description here

但是当我尝试访问在docker容器中运行的应用程序时,我无法访问。我正在从192.168.64.3:8085/lazy访问(8085,因为我已经在该端口进行了端口转发)。

0 个答案:

没有答案