I couldn't connect to a SQL Server container on Ubuntu

I created a SQL Server image on Ubuntu 24.10 using the following command:

docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=k$bBE833" \
   -p 1433:1433 --name sql1 --hostname sql1 \
   -d \
   mcr.microsoft.com/mssql/server:2022-latest \
   tail -f /dev/null

Then, I started an interactive bash session with:

docker exec -it <ContainerID> bash

I tried to connect to the SQL Server using:

/opt/mssql-tools18/bin/sqlcmd -S localhost,1433 -U sa -P k$bBE833

However, I received the following error:

Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server: Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server: TCP Provider: Error code 0x2749.
Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server: A network-related or instance-specific error has occurred while establishing a connection to localhost,1433. Server is not found or not accessible.

I’ve been struggling with this issue for days. Any help would be greatly appreciated. Thank you!

Hi

I wrote an article last year, perhaps can help you

I have no problem connecting to SQL Server container on Windows. I can run:

/opt/mssql-tools18/bin/sqlcmd -S localhost,1433 -U sa -P k$bBE833 -C  

But on Ubuntu, I’ve never been able to. Thanks!

This is a classic self sabotage.

If you had studied the image, you would have noticed that the entrypoint script starts whatever command is provided. Since you choose to replace the default command /opt/mssql/bin/sqlservr with tail -f /dev/null. the sql server is not started.

Furthermore, the $ in your password requires single quoting, otherwise it prints out the value of the variable $bBE833,. If this variable does not exist, your password is just k.

Something is realy off here.

1 Like

I’ve added tail -f /dev/null because the container exits immediately after being created.

If I try your command and remove your custom container command, it does not stop immediatly:

docker run --rm \
 -e "ACCEPT_EULA=Y" \
 -e "MSSQL_SA_PASSWORD=k$bBE833"  \
 -p 1433:1433 --name sql1 --hostname sql1 \
 mcr.microsoft.com/mssql/server:2022-latest

Note: I also removed -d as it makes it unnecessarily harder if the container is started in detached mode. I also added --rm so the container is deleted when stopped.

Update: my bad, it does. The reason is the $ in your password:

2025-04-24 19:31:57.34 spid19s     ERROR: Unable to set system administrator password: Password validation failed. The password does not meet SQL Server password policy requirements because it is too short. The password must be at least 8 characters..

Thank you. I’ve encountered a new problem: ‘sqlservr: This program requires a machine with at least 2000 megabytes of memory.’ I’m trying to install a SQL Server container on DigitalOcean.com, but I only have 254MB available. Is there a way to install the SQL Server container?

I helped with troubleshooting with the issues you caused by how you created the container,
But I can’t say anything about the sql server.

You have roughly 1/8th of the ram available that the sql server requires. The obvious answer is to use a Droplet that provides the required resources.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.