I am trying to connect to docker container of ms sql server 2017, through java spring boot application, In containerized environment its not getting connected and giving me error : 
    

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.

    However If I run Spring app locally it gets connected to Ms sql server container.
    
My spring boot application.properties:

spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.url=jdbc:sqlserver://localhost;databaseName=master
spring.datasource.username=sa
spring.datasource.password=Ms@12345
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql = true
    

# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.SQLServer2012Dialect


spring.jpa.hibernate.ddl-auto = update
spring.main.allow-bean-definition-overriding=true

Configured docker-compose.yml as below

    version: '3'
    services:
    
      myteamapp-mssqlserver:
        image: "mcr.microsoft.com/mssql/server:2017-latest"
        networks:
          - myteamapp-net
        volumes:
          - myteamapp-data:/var/opt/mssql
        ports:
          - 1433:1433
        environment:
          - SA_PASSWORD=Ms@12345
          - ACCEPT_EULA=Y
          - MSSQL_PID=Express
    
      myteamapp-app:
        image: webservices:latest
        networks:
          - myteamapp-net
        ports:
          - 8080:8080
        depends_on:
          - myteamapp-mssqlserver
            
        
      myteamapp-ui:
        image: myteamapp
        networks:
          - myteamapp-net
        depends_on:
          - myteamapp-app
        ports:
          - 4200:4200
        
    networks:
      myteamapp-net:
    
    volumes:
      myteamapp-data:
    
Let me know what is I am missing here.
0

There are 0 best solutions below