SQLCMD cannot connect to SQL instance (Container to Container)

Please assist.

I have two docker containers - running in the same network.
The 1st one hosts a sql server instance - which I can access successfully from the host.

However, a 2nd container - one same network - cannot access the sql instance in the 1st container?

I installed mssql-tools and now have sqlcmd tools on the 2nd container and this is the error I receive: I tried the server name, ip address - but to no avail ;-(

# ./sqlcmd -H 172.19.0.2,1433 -U sa -P Admin3970#xx -d TestDb
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2749.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online…

# ./sqlcmd -H localhost,1433 -U sa -P Admin3970#xx -d TestDb
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2749.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online…

# ./sqlcmd -H sqlx1,1433 -U sa -P Admin3970#xx -d TestDb
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2749.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online…

# ./sqlcmd -H sqlx1.myne,1433 -U sa -P Admin3970#xx -d TestDb
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2749.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online…

I just go it working, but have another connection issues :slight_smile:

./sqlcmd -S 172.19.0.2 -U sa -P Admin3970#xx -d TestDb

1> USE TestDb
2> GO
Changed database context to ‘TestDb’.
1> SELECT * FROM tblList
2> GO
Id Name


      1 Cat
      2 Dog
      3 Rabbit

(3 rows affected)
1>

@iwcoetzer : You got it working, but did not specify how. :frowning:
Any idea’s how you solved this 2 years ago? :slight_smile:

Hi
Shucks I will look for my old notes on this. I think it had to do with how networking was configured.

I have succeeded too. Problem was that I was calling sqlcmd on 127.0.0.1, which is wrong.
You should use the name of the docker-container to connect.

So, with this docker-compose file like this

version: '3.1'
services:
  sqlcmd:
    container_name: jnl_sqlcmd
    image: mcr.microsoft.com/mssql-tools:latest
    stdin_open: true
    environment:
      - MSSQL_SA_PASSWORD=mYSpecialDatab4se!
      - MSSQL_DATABASE=jnl_db
      - MSSQL_BACKUP="/opt/mssql/test.bak"
    volumes:
      - ../../import/jnl/dump.sql:/opt/mssql/dump.sql
  db: 
    container_name: jnl_mssql_compose
    image: mcr.microsoft.com/azure-sql-edge:latest
    environment: 
      - SA_PASSWORD=mYSpecialDatab4se!
      - ACCEPT_EULA=Y 
      - DATABASE_NAME=jnl_db
      - LOGICAL_NAME=jnl_hybris
      - DUMP_NAME=dump.sql
    ports: 
      - 1433:1433
    volumes:
      - ../../import/jnl:/mnt

I could connect through mysql with the following:

docker exec -it jnl_sqlcmd bash
sqlcmd -S jnl_mssql_compose -U SA -P mYSpecialDatab4se!

Good morning,
Yes, most likely something along the line of what you mentioned.

I found some shorthand notes I made, and noticed that I used an IP 172.19.0.2, so I must have configured the containers with specific IP addresses.

./sqlcmd -S 172.19.0.2 -U sa -P password -d TestDb