如何在DockedSpring应用程序中使用域名作为server.name

ao218c7q  于 2021-07-26  发布在  Java
关注(0)|答案(0)|浏览(272)

我在spring应用程序的Dockenization过程中遇到了问题。我的目标是,我希望它的server.address属性代表它所在服务器的域名,而不是docker容器名。实现这一目标的正确方法是什么?
这是我的docker撰写文件:

  1. version: "3"
  2. services:
  3. mysql:
  4. container_name: compose_mysql_1
  5. image: mysql:5.7
  6. environment:
  7. - MYSQL_ROOT_PASSWORD=example_password
  8. volumes:
  9. - mysql:/var/lib/mysql
  10. - ./sql:/docker-entrypoint-initdb.d/
  11. ports:
  12. - 3306:3306
  13. serviceregistry:
  14. container_name: serviceregistry
  15. image: portus.arrowhead-ci.tmit.bme.hu/arrowhead/serviceregistry:latest
  16. depends_on:
  17. - mysql
  18. volumes:
  19. - ./core_system_config/serviceregistry.properties:/serviceregistry/application.properties
  20. - ./tmit_certs/service_registry.p12:/serviceregistry/service_registry.p12
  21. ports:
  22. - 8443:8443
  23. volumes:
  24. mysql:
  25. external: true

这是我的相关application.properties文件:

  1. # Service Registry web-server parameters
  2. server.address=serviceregistry
  3. server.port=8443

我希望是:

  1. # Service Registry web-server parameters
  2. server.address=example.com
  3. server.port=8443

在application.properties中,如果我将其设置为容器名或域名,它将不会启动。我明白,这是因为在容器“example.com”中没有任何意义。

  1. . ____ _ __ _ _
  2. /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
  3. ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
  4. \\/ ___)| |_)| | | | | || (_| | ) ) ) )
  5. ' |____| .__|_| |_|_| |_\__, | / / / /
  6. =========|_|==============|___/=/_/_/_/
  7. :: Spring Boot :: (v2.1.5.RELEASE)
  8. 2019-11-14 11:40:34.081 INFO f75cd8bdc6c5 --- [ main] e.a.c.s.ServiceRegistryMain : Starting ServiceRegistryMain v4.1.3 on f75cd8bdc6c5 with PID 6 (/serviceregistry/arrowhead-serviceregistry.jar started by root in /)
  9. 2019-11-14 11:40:34.154 INFO f75cd8bdc6c5 --- [ main] e.a.c.s.ServiceRegistryMain : No active profile set, falling back to default profiles: default
  10. 2019-11-14 11:40:45.651 INFO f75cd8bdc6c5 --- [ main] e.a.c.f.ArrowheadFilter : SRAccessControlFilter is active
  11. 2019-11-14 11:40:55.648 INFO f75cd8bdc6c5 --- [ main] e.a.c.q.u.UriCrawlerTaskConfig : URI Crawler task scheduled.
  12. 2019-11-14 11:40:56.626 WARN f75cd8bdc6c5 --- [ main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
  13. 2019-11-14 11:40:59.163 INFO f75cd8bdc6c5 --- [ main] e.a.c.f.ArrowheadFilter : PayloadSizeFilter is active
  14. 2019-11-14 11:40:59.329 INFO f75cd8bdc6c5 --- [ main] .c.s.q.t.ProvidersReachabilityTaskConfig : Services end of validity task is not adjusted
  15. 2019-11-14 11:40:59.381 INFO f75cd8bdc6c5 --- [ main] .c.s.q.t.ProvidersReachabilityTaskConfig : Providers reachabilitiy task is not adjusted
  16. 2019-11-14 11:41:02.892 INFO f75cd8bdc6c5 --- [ main] e.a.c.ApplicationInitListener : Core system name: SERVICE_REGISTRY
  17. 2019-11-14 11:41:02.894 INFO f75cd8bdc6c5 --- [ main] e.a.c.ApplicationInitListener : Server mode: SECURED
  18. 2019-11-14 11:41:03.034 INFO f75cd8bdc6c5 --- [ main] e.a.c.ApplicationInitListener : Server CN: service_registry.testcloud2.aitia.arrowhead.eu
  19. 2019-11-14 11:41:03.409 ERROR f75cd8bdc6c5 --- [ main] o.a.c.u.LifecycleBase : Failed to start component [Connector[HTTP/1.1-8443]]
  20. org.apache.catalina.LifecycleException: Protocol handler start failed
  21. at org.apache.catalina.connector.Connector.startInternal(Connector.java:1008)
  22. at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
  23. at org.apache.catalina.core.StandardService.addConnector(StandardService.java:226)
  24. at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:259)
  25. at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:197)
  26. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.startWebServer(ServletWebServerApplicationContext.java:311)
  27. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:164)
  28. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:552)
  29. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
  30. at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
  31. at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
  32. at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
  33. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
  34. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
  35. at eu.arrowhead.core.serviceregistry.ServiceRegistryMain.main(ServiceRegistryMain.java:26)
  36. at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  37. at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  38. at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  39. at java.base/java.lang.reflect.Method.invoke(Unknown Source)
  40. at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
  41. at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
  42. at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
  43. at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
  44. Caused by: java.net.BindException: Cannot assign requested address
  45. at java.base/sun.nio.ch.Net.bind0(Native Method)
  46. at java.base/sun.nio.ch.Net.bind(Unknown Source)
  47. at java.base/sun.nio.ch.Net.bind(Unknown Source)
  48. at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source)
  49. at java.base/sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source)
  50. at org.apache.tomcat.util.net.NioEndpoint.initServerSocket(NioEndpoint.java:239)
  51. at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:213)
  52. at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup(AbstractEndpoint.java:1116)
  53. at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1202)
  54. at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:568)
  55. at org.apache.catalina.connector.Connector.startInternal(Connector.java:1005)
  56. ... 22 more
  57. 2019-11-14 11:41:03.445 WARN f75cd8bdc6c5 --- [ main] o.a.c.l.WebappClassLoaderBase : The web application [ROOT] appears to have started a thread named [HikariPool-2 housekeeper] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
  58. java.base@11.0.4/jdk.internal.misc.Unsafe.park(Native Method)
  59. java.base@11.0.4/java.util.concurrent.locks.LockSupport.parkNanos(Unknown Source)
  60. java.base@11.0.4/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(Unknown Source)
  61. java.base@11.0.4/java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(Unknown Source)
  62. java.base@11.0.4/java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(Unknown Source)
  63. java.base@11.0.4/java.util.concurrent.ThreadPoolExecutor.getTask(Unknown Source)
  64. java.base@11.0.4/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  65. java.base@11.0.4/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  66. java.base@11.0.4/java.lang.Thread.run(Unknown Source)
  67. 2019-11-14 11:41:03.482 ERROR f75cd8bdc6c5 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
  68. ***************************
  69. APPLICATION FAILED TO START
  70. ***************************
  71. Description:
  72. The Tomcat connector configured to listen on port 8443 failed to start. The port may already be in use or the connector may be misconfigured.
  73. Action:
  74. Verify the connector's configuration, identify and stop any process that's listening on port 8443, or configure this application to listen on another port.

我在想,主机联网模式将是正确的解决方案。我会重视所有的投入。
提前谢谢!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题