【发布时间】:2020-02-29 10:40:25
【问题描述】:
我正在另一个容器中使用 Dockerize spring boot 应用程序和 redis。我是这样运行redis容器的:docker run -d --name redis -p 6379:6379 redis
当我从 id 运行我的应用程序时,我没有问题,并且我的应用程序能够连接到 redis。
但是当我将我的应用程序作为容器运行时:docker run -p 8080:8080 shorturl,我遇到了下一个问题:java.net.ConnectException: Connection refused (Connection refused)。
这是我的 pom.xml:
<groupId>com.neueda.shorturl</groupId>
<artifactId>shortenurl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>shortenurl</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<finalName>shortenurl</finalName>
</build>
这是我的 application.yml 配置:
spring:
application:
name: shortenurl-neueda-assignment
redis:
host: localhost
port: 6379
有什么想法吗?
谢谢。
【问题讨论】:
-
这个答案可能有线索 -> stackoverflow.com/questions/56938511/…
标签: spring-boot redis jedis docker-image