Arti
Arti

Reputation: 7762

Python connect to firebird docker database

I have a mydb.fdb file, how do I can load it into docker container and then connect to it from python. I do the following in my docker-compose:

version: '2'

services:
  firebird:
    image: jacobalberty/firebird
    environment:
      ISC_PASSWORD: pass
    volumes:
      - ./database:/databases

Then I do:

docker exec -it <container-id> bin/bash

And I see my .fdb file inside /databases folder in container, but when I do commands inside container:

cd /usr/local/firebird/bin
./isql
SQL> CONNECT "/databases/mydb.FDB" user sysdba password masterkey;

I received:

Use of database at location /databases/mydb.FDB is not allowed by server configuration

And also I don't understand how to connect to this db via fdb python module. I do:

import fdb

con = fdb.connect(
    host='0.0.0.0',
    port='3050', 
    database='mydb.FDB',
    user='sysdba', 
    password='masterkey')

And received:

raise Exception("The location of Firebird Client Library could not be determined.")

Upvotes: 3

Views: 2480

Answers (1)

Mark Rotteveel
Mark Rotteveel

Reputation: 109000

You have two different problems in your question, in the future, please make sure to ask them as separate questions.

As to your first problem, the setup of the Firebird docker image by default expects databases in the location /firebird/data, and explicitly configures Firebird to restrict access to only that location. If you want to use a different location, then you must set the environment variable DBPATH to the correct path. See also issue 12, the Dockerfile and the build.sh of the image. This option doesn't seem to be documented; I have left a comment on that ticket.

As to your second problem, it has two parts. One, you can't use 0.0.0.0 to connect, that is just a shorthand for "all ip addresses of this host", it can only be used when listening for connections, not when connecting. You will need to use 127.0.0.1 or localhost when connecting from the machine running docker.

On top of that, the error suggests that you have no Firebird native client installed. The FDB driver requires fbclient.dll (Windows) or libfbclients.so (Linux). You either need to install the Firebird native client, or switch to pyfirebirdsql, which is a Firebird driver in pure Python (it implements the Firebird protocol in Python).

Upvotes: 3

Related Questions