我试图使用docker来运行我的jhipster微服务。
在没有Docker的情况下运行时我没有问题。但是现在我在尝试使用docker运行我的微服务时遇到了一些问题。
每次执行
在我的UAA服务器上的docker-compose -f app.yml up
命令,它在运行UAA服务器时显示此错误。
uaa-app_1 | 2017-04-17 07:38:59.725 DEBUG 6 --- [ main] i.c.f.uaa.config.CacheConfiguration : No cache
uaa-app_1 | 2017-04-17 07:39:06.897 DEBUG 6 --- [ main] i.c.f.u.c.apidoc.SwaggerConfiguration : Starting Swagger
uaa-app_1 | 2017-04-17 07:39:06.914 DEBUG 6 --- [ main] i.c.f.u.c.apidoc.SwaggerConfiguration : Started Swagger in 16 ms
uaa-app_1 | 2017-04-17 07:39:07.004 DEBUG 6 --- [ main] i.c.f.uaa.config.DatabaseConfiguration : Configuring Mongobee
uaa-app_1 | 2017-04-17 07:39:07.020 INFO 6 --- [ main] com.github.mongobee.Mongobee : Mongobee has started the data migration sequence..
uaa-app_1 | 2017-04-17 07:39:37.056 WARN 6 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongobee' defined in class path resource [id/co/fifgroup/uaa/config/DatabaseConfiguration.class]: Invocation of init method failed; nested exception is com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]
uaa-app_1 | 2017-04-17 07:39:37.074 INFO 6 --- [ main] i.c.f.uaa.config.CacheConfiguration : Closing Cache Manager
uaa-app_1 | 2017-04-17 07:39:37.129 ERROR 6 --- [ main] o.s.boot.SpringApplication : Application startup failed
uaa-app_1 |
uaa-app_1 | org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongobee' defined in class path resource [id/co/fifgroup/uaa/config/DatabaseConfiguration.class]: Invocation of init method failed; nested exception is com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]
这是我在Docker目录中的UAA服务器app.yml。
version: '2'
services:
uaa-app:
image: uaa
external_links:
- uaa-mongodb:mongodb
- jhipster-registry:registry
environment:
- SPRING_PROFILES_ACTIVE=dev,swagger
- SPRING_CLOUD_CONFIG_URI=http://admin:admin@registry:8761/config
- SPRING_DATA_MONGODB_URI=mongodb://mongodb:27017
- SPRING_DATA_MONGODB_DATABASE=uaa
- JHIPSTER_SLEEP=15 # gives time for the database to boot before the application
uaa-mongodb:
extends:
file: mongodb.yml
service: uaa-mongodb
jhipster-registry:
extends:
file: jhipster-registry.yml
service: jhipster-registry
environment:
- SPRING_CLOUD_CONFIG_SERVER_NATIVE_SEARCH_LOCATIONS=file:./central-config/docker-config/
uaa-mongodb和jhipster-registry与docker配合得很好,但是我的UAA服务器无法连接到uaa-mongodb。
为什么错误一直说我使用localhost:27017甚至你试图在application-dev.yml中更改 SPRING_DATA_MONGODB_URI 和 spring.data.mongodb.uri 和application-prod.yml成差异值。
有人可以帮我解决这个问题......
答案 0 :(得分:0)
回答我自己的问题,这就是我用我的剧本做的一切。
我将app.yml文件更改为
version: '2'
services:
uaa:
image: uaa:latest
external_links:
- uaa-mongodb:mongodb
- jhipster-registry:registry
links :
- uaa-mongodb:mongodb
environment:
- SPRING_PROFILES_ACTIVE=prod,swagger,test
- SPRING_CLOUD_CONFIG_URI=http://admin:admin@registry:8761/config
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://admin:admin@registry:8761/config
- SPRING_DATA_MONGODB_HOST=mongodb
- SPRING_DATA_MONGODB_PORT=27017
- SPRING_DATA_MONGODB_DATABASE=uaa
- JHIPSTER_SLEEP=15 # gives time for the database to boot before the application
jhipster-registry:
extends:
file: jhipster-registry.yml
service: jhipster-registry
environment:
- SPRING_CLOUD_CONFIG_SERVER_NATIVE_SEARCH_LOCATIONS=file:./central-config/docker-config/
uaa-mongodb:
extends:
file: mongodb.yml
service: uaa-mongodb
和我的application-pro.yml进入
eureka:
instance:
prefer-ip-address: true
client:
enabled: true
healthcheck:
enabled: true
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: ${EUREKA_CLIENT_SERVICEURL_DEFAULTZONE}
spring:
devtools:
restart:
enabled: false
livereload:
enabled: false
data:
mongodb:
host: ${SPRING_DATA_MONGODB_HOST}
port: ${SPRING_DATA_MONGODB_PORT}
database: ${SPRING_DATA_MONGODB_DATABASE}
现在我的UAA服务器成功连接到容器化的mongodb数据库。 但现在我有了新的错误..
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
uaa_1 | at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:111)
uaa_1 | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
uaa_1 | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59)
uaa_1 | at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77)
uaa_1 | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
uaa_1 | at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:815)
uaa_1 | at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:104)
uaa_1 | at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
uaa_1 | at java.util.concurrent.FutureTask.run(FutureTask.java:266)
uaa_1 | at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
uaa_1 | at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
uaa_1 | at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
uaa_1 | at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
uaa_1 | at java.lang.Thread.run(Thread.java:745)