Could not connect to SQL Server Docker Windows Container in Azure VM (v3)

I'm using Azure VM type V3. I have a Dockerfile for building sqlserver instance. I used this in my local pc and it worked well and now I'd like to try it in my VM but I'm having errors such as:

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: The wait operation timed out.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired. 

Note: I set the connection timeout to 0 already.

Here is my Dockerfile:

# Dockerfile for sql
FROM microsoft/mssql-server-windows-developer:latest

# Metadata indicating an image maintainer.
LABEL maintainer="me@gmail.com"
 
WORKDIR C:/Database
    
EXPOSE 3000 3001 3002 1433 1434 1435

#CMD [ "npm.cmd", "start" ]
CMD [ "cmd" ]
#########################################################

I build and run it with this script:

docker build -t sql .
docker run --name=sql-container1 -it -p 1435:1435 -e sa_password=P@ssw0rd123 -e ACCEPT_EULA=Y sql:latest

I could not connect using Sql Server Management Studio and I also encounter the error every time I try to connect using SqlCmd with this command:

sqlcmd -S localhost,1435 -U "SA" -P "P@ssw0rd123"

I also tried this:

sqlcmd -S localhost,1435 -U SA -P P@ssw0rd123
sqlcmd -U SA -P P@ssw0rd123

Nothing worked. I've enabled, TCP in the Sql Server Configuration Manager and also I could ping the ip address. I tried using telnet but also failed at my attempt at telnet command:

telnet ipaddress port 

I also tried getting the IP and Port by using sqlcmd utility:

sqlcmd -q "SELECT e.name as ProtocolName, ec.local_tcp_port as Port,ec.local_net_address as IP FROM    sys.endpoints e LEFT JOIN    sys.dm_exec_connections ec ON  ec.endpoint_id = e.endpoint_id where       e.name = 'TSQL Default TCP' GROUP BY     e.name     ,ec.local_tcp_port     ,ec.local_net_address "

But the result was null IP and null Port

IP and Port are null

The docker container is in the VM, I'm using SQL Server Developer Edition (latest) in the VM. Everything is in the VM. I also tried opening the port in Windows Defender Firewall with Advanced Security. I don't know what is blocking this. Please help, thanks in advance.



Read more here: https://stackoverflow.com/questions/64399098/could-not-connect-to-sql-server-docker-windows-container-in-azure-vm-v3

Content Attribution

This content was originally published by Sol at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: