# Issue connecting to SQL Server docker instance with ignition?

**URL:** <https://forum.inductiveautomation.com/t/issue-connecting-to-sql-server-docker-instance-with-ignition/98517>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [November 12, 2024, 3:47pm UTC](https://forum.inductiveautomation.com/t/issue-connecting-to-sql-server-docker-instance-with-ignition/98517 "2024-11-12T15:47:15Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [November 12, 2024, 3:47pm UTC](https://forum.inductiveautomation.com/t/issue-connecting-to-sql-server-docker-instance-with-ignition/98517/1 "2024-11-12T15:47:15Z")

</div>

I am new to docker so I am probably missing something silly.

Here is my compose file -

```python
services:
  sqlserver:
    image: mcr.microsoft.com/mssql/server:2019-latest
    container_name: sql_server
    ports:
      - "1435:1433"
    environment:
      - ACCEPT_EULA=Y
      - MSSQL_SA_PASSWORD=SomeStrong!Passw0rd
    networks:
      - app-network
    volumes:
      - sql_data:/var/opt/mssql

  ignition:
    image: inductiveautomation/ignition:8.1.43
    container_name: ignition
    ports:
      - "8089:8088"
    depends_on: # Ensures SQL Server starts first
      - sqlserver
    environment:
      GATEWAY_ADMIN_PASSWORD: password
      IGNITION_EDITION: standard
      ACCEPT_IGNITION_EULA: "Y"
    networks:
      - app-network
    volumes:
      - gateway-data:/usr/local/bin/ignition/data

networks:
  app-network:
    driver: bridge

volumes:
  sql_data:
  gateway-data:

```

I am able to see and access my Ignition gateway.

I am able to login to this SQL Server instance via the SSMS on my local computer by going to 127.0.0.1,1435. I do need to trust server certificate but otherwise works.

When I try to connect to SQL Server via Ignition by making a database connection I keep getting  
`java.sql.SQLException: Cannot create PoolableConnectionFactory (The TCP/IP connection to the host localhost, port 1435 has failed. Error: "Connection refused. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".)`

I tried adding the `trustServerCertificate=true` to the connection string but still cannot connect.

I don't know what else to try or do. Any ideas?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 12, 2024, 3:51pm UTC](https://forum.inductiveautomation.com/t/issue-connecting-to-sql-server-docker-instance-with-ignition/98517/2 "2024-11-12T15:51:14Z")

</div>

What host name are you using in your gateway's DB connection URL? (Should be the container name, not localhost.)

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [November 12, 2024, 4:13pm UTC](https://forum.inductiveautomation.com/t/issue-connecting-to-sql-server-docker-instance-with-ignition/98517/3 "2024-11-12T16:13:08Z")

</div>

I changed my container\_name and added a hostname like

```python
container_name: sqlserver
hostname: sqlserver

```

My JBDC conn string is  
`jdbc:sqlserver://sqlserver\MSSQLSERVER:1435`

I am still getting the same error regarding TCP/IP.

I did notice through SSMS I need to do `127.0.0.1, 1435`, trying `sqlserver` or `sqlserver,1435` does not reach it so I am curious if it is a network thing. I have not configured the `app-network` at all outside of making it.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 12, 2024, 4:14pm UTC](https://forum.inductiveautomation.com/t/issue-connecting-to-sql-server-docker-instance-with-ignition/98517/4 "2024-11-12T16:14:32Z")

</div>

Not sure. But URLs are not supposed to have backslashes.

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [November 12, 2024, 4:43pm UTC](https://forum.inductiveautomation.com/t/issue-connecting-to-sql-server-docker-instance-with-ignition/98517/5 "2024-11-12T16:43:12Z")

</div>

On ours we use

> jdbc:sqlserver://localhost\MSSQLSERVER:1433

Yours should end with 1435

With the extra connection settings of

> databaseName=NameOfDatabase;trustServerCertificate=true

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [November 12, 2024, 5:19pm UTC](https://forum.inductiveautomation.com/t/issue-connecting-to-sql-server-docker-instance-with-ignition/98517/6 "2024-11-12T17:19:34Z")

</div>

Try with only `jdbc:sqlserver://sqlserver:1435`

Make sure to configure the database name in the extra connection properties

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [November 12, 2024, 6:17pm UTC](https://forum.inductiveautomation.com/t/issue-connecting-to-sql-server-docker-instance-with-ignition/98517/7 "2024-11-12T18:17:38Z")

</div>

I figured it out. I stopped the SQL Service running on my local computer. I also have Ignition running locally and figured I could try connecting from that gateway. That worked - with a  
`jdbc:sqlserver://localhost\MSSQLSERVER:1435` and `trustServerCertificate=true`.

However the above was not working with my dockerized version of SQL Server. I know @pturmel and mentioned using the name, so I tried `jdbc:sqlserver://sqlserver\MSSQLSERVER:1435` and `jdbc:sqlserver://sqlserver:1435` but no dice.

I took a guess that this part

```python
    ports:
      - "1435:1433"

```

meant from the outside I need to use 1435 but inside the docker network `app-network` I am using, I can use 1433 and that did - so it ended up being `jdbc:sqlserver://sqlserver` (without the `\MSSQLSERVER` - it does not work with this - thanks @pascal.fragnoud )

---

<div class="post-metadata">

**Author:** ![David\_Stone](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/david_stone/32/79749_2.png) [@David\_Stone](https://forum.inductiveautomation.com/u/David_Stone)\
**Post date:** [November 12, 2024, 8:33pm UTC](https://forum.inductiveautomation.com/t/issue-connecting-to-sql-server-docker-instance-with-ignition/98517/8 "2024-11-12T20:33:26Z")

</div>

As a general rule with docker instances accessing other docker instances, I have been using the `host.docker.internal` instead of using `localhost` as the hostname. This essentially routes the network traffic as if you are querying the base machine for the resource, which then works as docker exposes the ports to the base machine as normal. This works when running MySQL on the same docker as Ignition, and hasn't broken in a couple of years.

---

<div class="post-metadata">

**Author:** ![Gaurav.Shitole](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/gaurav.shitole/32/72050_2.png) [@Gaurav.Shitole](https://forum.inductiveautomation.com/u/Gaurav.Shitole)\
**Post date:** [August 26, 2025, 9:22pm UTC](https://forum.inductiveautomation.com/t/issue-connecting-to-sql-server-docker-instance-with-ignition/98517/9 "2025-08-26T21:22:33Z")

</div>

Is there any explanation why my containerized database can connect successfully from SSMS using either **`aliasedName:mappedPort`** or **`serviceName:mappedPort`** , but the same **`aliasedName:mappedPort`** does not work on Ignition gateway?

In Ignition, I get the following error:

```python
Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Caused by: java.net.ConnectException: Connection refused

```

However, the connection works if I use:

- **`host.docker.internal:mappedPort`** on the gateway OR

- **`aliasedName:defaultPort`** or **`serviceName:defaultPort`**

Why does gateway fail with `aliasedName:mappedPort` while SSMS succeeds?

---

<div class="post-metadata">

**Author:** ![kcollins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kcollins/32/19646_2.png) [@kcollins](https://forum.inductiveautomation.com/u/kcollins)\
**Post date:** [August 29, 2025, 2:26am UTC](https://forum.inductiveautomation.com/t/issue-connecting-to-sql-server-docker-instance-with-ignition/98517/10 "2025-08-29T02:26:23Z")

</div>

> [@Gaurav.Shitole](#):
>
> Why does gateway fail with `aliasedName:mappedPort` while SSMS succeeds?

The MSSQL service is listening on a given port, i.e. `1433/tcp`. If this is in a compose stack as service "mssql", then you'd connect to it from another service in the stack by name and port, i.e. `mssql:1433`. Whatever port you're using with SSMS is the port that is listening only on your host interface. This is why it will work when you point Ignition to your host interface (via `host.docker.internal`) on the published port. Ideally, you'll want to connect Ignition via **`serviceName:defaultPort`** (your description) instead of having it loopback through your host.

---

<div class="post-metadata">

**Author:** ![Gaurav.Shitole](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/gaurav.shitole/32/72050_2.png) [@Gaurav.Shitole](https://forum.inductiveautomation.com/u/Gaurav.Shitole)\
**Post date:** [August 29, 2025, 2:20pm UTC](https://forum.inductiveautomation.com/t/issue-connecting-to-sql-server-docker-instance-with-ignition/98517/11 "2025-08-29T14:20:53Z")

</div>

Oh ok, thank you for the explanation.

So, even if I configure 2–3 MSSQL services (each mapped to a different host port), I should still connect using the **`serviceName:defaultPort`** approach, right?

For example:

```python
mssql1:
  ports:
    - 1435:1433

mssql2:
  ports:
    - 1436:1433

mssql3:
  ports:
    - 1437:1433

```

So, when connecting to two different services, I should use:

- `mssql1:1433`

- `mssql2:1433`

and **not** `host.docker.internal:1435` & `host.docker.internal:1436`.

---

<div class="post-metadata">

**Author:** ![kcollins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kcollins/32/19646_2.png) [@kcollins](https://forum.inductiveautomation.com/u/kcollins)\
**Post date:** [August 29, 2025, 3:02pm UTC](https://forum.inductiveautomation.com/t/issue-connecting-to-sql-server-docker-instance-with-ignition/98517/12 "2025-08-29T15:02:25Z")

</div>

Yes, you've got it. Docker Compose creates a default network for your stack within which services can connect to each other. The only reason you need/want to publish ports out to your host is only for your own management of those DBs via SSMS. The port publishes aren't needed at all for service-to-service communication.

---

<div class="post-metadata">

**Author:** ![Curlyandshemp](https://avatars.discourse-cdn.com/v4/letter/c/bcef8e/32.png) [@Curlyandshemp](https://forum.inductiveautomation.com/u/Curlyandshemp)\
**Post date:** [November 6, 2025, 3:42pm UTC](https://forum.inductiveautomation.com/t/issue-connecting-to-sql-server-docker-instance-with-ignition/98517/13 "2025-11-06T15:42:06Z")

</div>

I was having same issues using [//localhost](https://localhost) and using host.docker.internal resolved it,

Thanks for this
