# SQLCMD cannot connect to SQL instance (Container to Container)

**URL:** <https://forums.docker.com/t/sqlcmd-cannot-connect-to-sql-instance-container-to-container/89401>\
**Category:** General\
**Tags:** docker\
**Created:** [February 21, 2020, 8:28am UTC](https://forums.docker.com/t/sqlcmd-cannot-connect-to-sql-instance-container-to-container/89401 "2020-02-21T08:28:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![iwcoetzer](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/iwcoetzer/32/26550_2.png) [@iwcoetzer](https://forums.docker.com/u/iwcoetzer)\
**Post date:** [February 21, 2020, 8:28am UTC](https://forums.docker.com/t/sqlcmd-cannot-connect-to-sql-instance-container-to-container/89401/1 "2020-02-21T08:28:50Z")

</div>

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…

#

---

<div class="post-metadata">

**Author:** ![iwcoetzer](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/iwcoetzer/32/26550_2.png) [@iwcoetzer](https://forums.docker.com/u/iwcoetzer)\
**Post date:** [February 21, 2020, 8:35am UTC](https://forums.docker.com/t/sqlcmd-cannot-connect-to-sql-instance-container-to-container/89401/2 "2020-02-21T08:35:53Z")

</div>

> [@iwcoetzer](#):
>
> d mssql-tools and now have sqlcmd tools on the 2nd container and this is the error I receive: I

I just go it working, but have another connection issues 🙂

# ./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\>

---

<div class="post-metadata">

**Author:** ![peterbriers](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/peterbriers/32/36810_2.png) [@peterbriers](https://forums.docker.com/u/peterbriers)\
**Post date:** [October 9, 2022, 10:16am UTC](https://forums.docker.com/t/sqlcmd-cannot-connect-to-sql-instance-container-to-container/89401/3 "2022-10-09T10:16:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![iwcoetzer](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/iwcoetzer/32/26550_2.png) [@iwcoetzer](https://forums.docker.com/u/iwcoetzer)\
**Post date:** [October 9, 2022, 10:57am UTC](https://forums.docker.com/t/sqlcmd-cannot-connect-to-sql-instance-container-to-container/89401/4 "2022-10-09T10:57:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![peterbriers](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/peterbriers/32/36810_2.png) [@peterbriers](https://forums.docker.com/u/peterbriers)\
**Post date:** [October 10, 2022, 5:36am UTC](https://forums.docker.com/t/sqlcmd-cannot-connect-to-sql-instance-container-to-container/89401/5 "2022-10-10T05:36:47Z")

</div>

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

```auto
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:

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

```

---

<div class="post-metadata">

**Author:** ![iwcoetzer](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/iwcoetzer/32/26550_2.png) [@iwcoetzer](https://forums.docker.com/u/iwcoetzer)\
**Post date:** [October 10, 2022, 6:38am UTC](https://forums.docker.com/t/sqlcmd-cannot-connect-to-sql-instance-container-to-container/89401/6 "2022-10-10T06:38:39Z")

</div>

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
