Trying to spin up an mssql server with a docker-compose file:
version: "3.7"
services:
sqlserver:
image: mcr.microsoft.com/mssql/server:2017-latest
container_name: sqlserver
user: root
ports:
- "1433:1433"
environment:
SA_USERNAME: sa
SA_PASSWORD: Dev1234!
ACCEPT_EULA: Y
MSSQL_AGENT_ENABLED: 'true'
volumes:
- ./volumes/data2:/var/opt/mssql/data
- ./volumes/backup:/var/opt/mssql/Backup
The server is up and running successfully, But when tried to connect with PowerShell script code:
$connectionString = "Data Source=localhost,1433;User ID=sa;Password=Dev1234!;"
$connection = New-Object System.Data.SqlClient.SqlConnection($connectionString)
$connection.Open();
It throws error like:
"A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name
is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - The
remote computer refused the network connection.)"
That is, it fails when trying to connect with 'localhost' as host, it is successfully connecting when "127.0.0.1" is specified as host.
The same happens when I tried to connect with SQL server management studio.
I could able to connect with 'localhost' to db with udl file also:
My docker engine is running in wsl, an ubuntu distro specifically. There is MySQL and different other servers already spun up which I can access with localhost.
Is there anything I need to specify in docker-compose to make this work? When checking documentation, there are no params aligned to it as I see.