I have to different containers, a SQLServer container and a Spring Boot application.
If I execute the SQLServer container and run the Spring Boot application outside the container they connect, but when I create the Spring Boot container it fails.
This is the error:
2024-06-27 14:34:06 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.".
2024-06-27 14:34:06 at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:231)
2024-06-27 14:34:06 at com.microsoft.sqlserver.jdbc.SQLServerException.convertConnectExceptionToSQLServerException(SQLServerException.java:282)
I have an example using mySql working (with two containers), but with SQLServer it fails. This are the steps I follow to run both containers:
I create a network for the communication
docker network create wcas-network
I run my SQLServer container (after it I create tables and data):
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=Password!" -p 1433:1433 --network wcas-network --name sqlserver -d mcr.microsoft.com/mssql/server:2022-latest
Then I run my Spring Boot container:
mvn clean install -DskipTests
docker build -t wcas .
docker run -d -p 8080:8080 --network wcas-network --name wcas wcas
And then I see the error I attached and as I said, if I run locally my Spring Boot application it works. With a sqlServer client (like Heidi) I can connect and see the data fine too.