我正在尝试使用docker-compose --build命令构建应用程序。但是,出现以下错误:
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name
'influxDB' defined in class path resource [com/order/app/config/InfluxDatabaseConfig.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.influxdb.InfluxDB]:
Factory method 'influxDB' threw exception;
nested exception is org.influxdb.InfluxDBIOException:
java.net.ConnectException: Failed to connect to localhost/127.0.0.1:8086
这是我的docker-compose.yml: version: '3'
services:
influx:
image: influxdb
container_name: influxdb
environment:
INFLUXDB_DB: test
INFLUXDB_ADMIN_USER: admin
INFLUXDB_ADMIN_PASSWORD: admin
INFLUXDB_HTTP_AUTH_ENABLED: "true"
ports:
- 8081:8081/tcp
backend:
container_name: order-app
image: order-app
build: .
ports:
- "8080:8080"
depends_on:
- influx
这是我的InfluxDatabaseConfig类:@Configuration
@EnableConfigurationProperties(InfluxDBProperties.class)
public class InfluxDatabaseConfig {
@Bean
public InfluxDB influxDB() {
InfluxDB connection = InfluxDBFactory.connect("http://localhost:8086", "admin", "admin");
connection.createDatabase("test");
connection.setDatabase("test");
return connection;
}
}
application.properties文件:server.port=8080
spring.influxdb.database=test
spring.influxdb.url=http://localhost:8086
spring.influxdb.username=admin
spring.influxdb.password=admin
spring.influxdb.retention-policy=autogen
spring.influxdb.gzip=true
有人知道我的代码中可能出什么问题吗?谢谢您的帮助。 最佳答案
您的Influx容器和后端在两个不同的容器中运行,这意味着它们是两台不同的计算机,每台计算机都有自己的IP。
您不能使用localhost:8086
从后端容器调用influx数据库
要进入influx数据库,您必须调用influx容器ip或名称或服务名称
还将流入的暴露端口更新为8086:8086
在您的情况下,将http://localhost:8086
的值更改为influx:8086
并尝试一下
关于spring - InfluxDB docker镜像不适用于我的Spring Boot应用程序镜像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/63615117/