Ignition Docker with sql database

Dear,

How do we need to do to connect a gateway running in docker with a sql database (Also in docker).

My connection stay always in faulted. When trying to connect with workbench the connection is working.

Regards

Use the container name. If the containers are on the same docker network, the hostname is the container name.

1 Like

If you’re running independent containers, you could try having Ignition connect to the database by looping back to your host via host.docker.internal. That name will resolve to the IP of your host system, against which you can then connect to the published port you setup for the database (which you’re using to connect via workbench).

5 Likes

Thank you so much for this :smiley:
I spent all morning trying to figure out how to connect to a dockerized database from a dockerized ignition !

Just check that new Elective course

I found it very usefull when starting with docker

3 Likes

Thanks, I'll check this out when I can find the time.

I'll also augment that as of Docker Engine 20.10, you can also use host.docker.internal mapping on Linux (where it was previously only available on Docker Desktop). You do have to add an extra_hosts mapping to your container definition though, such as:

docker run ... --add-host "host.docker.internal:host-gateway" ...

... or in your Compose YAML:

services:
  gateway:
    ...
    extra_hosts:
      - "host.docker.internal:host-gateway"
    ....

With this, the hostname host.docker.internal will resolve to your docker0 bridge IP on the host.

1 Like