我开始玩Docker。我正在尝试在与docker上的mssql-server-linux连接的Docker上运行Spring Boot应用程序。我正在配置并运行mssql服务器。我的应用程序设置了数据库端口,当我在IntelliJ中运行此应用程序时,一切正常。另外,当我构建应用程序'./mvnw install dockerfile:build'命令时,一切正常。还在构建期间将实体添加到数据库。当我尝试运行app'docker run'命令时,出现此异常:
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
出什么问题了?
我的Spring Boot应用程序属性:
spring.datasource.username=sa
spring.datasource.password=ABCabc123!
spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=DockerApp
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
spring.jpa.hibernate.ddl-auto=update
Dockerfile:
FROM java:8
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} docker-app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-
jar","/docker-app.jar"]
CMD ["-start"]
我在pom.xml中的构建选项:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.3.6</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
</execution>
</executions>
<configuration>
<repository>my-repo</repository>
<tag>${project.version}</tag>
<pullNewerImage>false</pullNewerImage>
<useMavenSettingsForAuth>true</useMavenSettingsForAuth>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
</plugins>
</build>