我正在使用Dockerize春季启动应用程序,并在另一个容器中进行Redis。我以这种方式运行redis容器:docker run -d --name redis -p 6379:6379 redis
当我从id运行我的应用程序时,我没有任何问题,并且我的应用程序能够连接到Redis。
但是,当我将我的应用作为容器运行时:docker run -p 8080:8080 shortenurl,我遇到了下一个问题: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
有什么想法吗?
谢谢。