我在spring应用程序的Dockenization过程中遇到了问题。我的目标是,我希望它的server.address属性代表它所在服务器的域名,而不是docker容器名。实现这一目标的正确方法是什么?
这是我的docker撰写文件:
version: "3"
services:
mysql:
container_name: compose_mysql_1
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=example_password
volumes:
- mysql:/var/lib/mysql
- ./sql:/docker-entrypoint-initdb.d/
ports:
- 3306:3306
serviceregistry:
container_name: serviceregistry
image: portus.arrowhead-ci.tmit.bme.hu/arrowhead/serviceregistry:latest
depends_on:
- mysql
volumes:
- ./core_system_config/serviceregistry.properties:/serviceregistry/application.properties
- ./tmit_certs/service_registry.p12:/serviceregistry/service_registry.p12
ports:
- 8443:8443
volumes:
mysql:
external: true
这是我的相关application.properties文件:
# Service Registry web-server parameters
server.address=serviceregistry
server.port=8443
我希望是:
# Service Registry web-server parameters
server.address=example.com
server.port=8443
在application.properties中,如果我将其设置为容器名或域名,它将不会启动。我明白,这是因为在容器“example.com”中没有任何意义。
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.5.RELEASE)
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 /)
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
2019-11-14 11:40:45.651 INFO f75cd8bdc6c5 --- [ main] e.a.c.f.ArrowheadFilter : SRAccessControlFilter is active
2019-11-14 11:40:55.648 INFO f75cd8bdc6c5 --- [ main] e.a.c.q.u.UriCrawlerTaskConfig : URI Crawler task scheduled.
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
2019-11-14 11:40:59.163 INFO f75cd8bdc6c5 --- [ main] e.a.c.f.ArrowheadFilter : PayloadSizeFilter is active
2019-11-14 11:40:59.329 INFO f75cd8bdc6c5 --- [ main] .c.s.q.t.ProvidersReachabilityTaskConfig : Services end of validity task is not adjusted
2019-11-14 11:40:59.381 INFO f75cd8bdc6c5 --- [ main] .c.s.q.t.ProvidersReachabilityTaskConfig : Providers reachabilitiy task is not adjusted
2019-11-14 11:41:02.892 INFO f75cd8bdc6c5 --- [ main] e.a.c.ApplicationInitListener : Core system name: SERVICE_REGISTRY
2019-11-14 11:41:02.894 INFO f75cd8bdc6c5 --- [ main] e.a.c.ApplicationInitListener : Server mode: SECURED
2019-11-14 11:41:03.034 INFO f75cd8bdc6c5 --- [ main] e.a.c.ApplicationInitListener : Server CN: service_registry.testcloud2.aitia.arrowhead.eu
2019-11-14 11:41:03.409 ERROR f75cd8bdc6c5 --- [ main] o.a.c.u.LifecycleBase : Failed to start component [Connector[HTTP/1.1-8443]]
org.apache.catalina.LifecycleException: Protocol handler start failed
at org.apache.catalina.connector.Connector.startInternal(Connector.java:1008)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.addConnector(StandardService.java:226)
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:259)
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:197)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.startWebServer(ServletWebServerApplicationContext.java:311)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:164)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:552)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
at eu.arrowhead.core.serviceregistry.ServiceRegistryMain.main(ServiceRegistryMain.java:26)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.net.BindException: Cannot assign requested address
at java.base/sun.nio.ch.Net.bind0(Native Method)
at java.base/sun.nio.ch.Net.bind(Unknown Source)
at java.base/sun.nio.ch.Net.bind(Unknown Source)
at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source)
at java.base/sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source)
at org.apache.tomcat.util.net.NioEndpoint.initServerSocket(NioEndpoint.java:239)
at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:213)
at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup(AbstractEndpoint.java:1116)
at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1202)
at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:568)
at org.apache.catalina.connector.Connector.startInternal(Connector.java:1005)
... 22 more
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:
java.base@11.0.4/jdk.internal.misc.Unsafe.park(Native Method)
java.base@11.0.4/java.util.concurrent.locks.LockSupport.parkNanos(Unknown Source)
java.base@11.0.4/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(Unknown Source)
java.base@11.0.4/java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(Unknown Source)
java.base@11.0.4/java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(Unknown Source)
java.base@11.0.4/java.util.concurrent.ThreadPoolExecutor.getTask(Unknown Source)
java.base@11.0.4/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.base@11.0.4/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.base@11.0.4/java.lang.Thread.run(Unknown Source)
2019-11-14 11:41:03.482 ERROR f75cd8bdc6c5 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
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.
Action:
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.
我在想,主机联网模式将是正确的解决方案。我会重视所有的投入。
提前谢谢!
暂无答案!
目前还没有任何答案,快来回答吧!