Python 连接到 firebird docker 数据库
Python connect to firebird docker database
我有一个 mydb.fdb
文件,如何将它加载到 docker 容器中,然后从 python 连接到它。我在 docker-compose 中执行以下操作:
version: '2'
services:
firebird:
image: jacobalberty/firebird
environment:
ISC_PASSWORD: pass
volumes:
- ./database:/databases
然后我做:
docker exec -it <container-id> bin/bash
而且我在容器的 /databases
文件夹中看到我的 .fdb
文件,但是当我在容器中执行命令时:
cd /usr/local/firebird/bin
./isql
SQL> CONNECT "/databases/mydb.FDB" user sysdba password masterkey;
我收到了:
Use of database at location /databases/mydb.FDB is not allowed by server configuration
而且我不明白如何通过 fdb python module 连接到这个数据库。我愿意:
import fdb
con = fdb.connect(
host='0.0.0.0',
port='3050',
database='mydb.FDB',
user='sysdba',
password='masterkey')
并收到:
raise Exception("The location of Firebird Client Library could not be
determined.")
您的问题有两个不同的问题,以后请务必将它们作为单独的问题提出。
关于您的第一个问题,Firebird docker 图像的设置默认需要位置 /firebird/data
中的数据库,并明确配置 Firebird 以限制仅访问该位置。如果要使用不同的位置,则必须将环境变量 DBPATH
设置为正确的路径。另见图像的 issue 12, the Dockerfile and the build.sh。这个选项似乎没有记录;我已对该票发表评论。
关于你的第二个问题,它分为两个部分。一,不能用0.0.0.0来连接,那只是一个shorthand for "all ip addresses of this host",只能在监听连接的时候用,不能在连接的时候用。从机器 运行 docker.
连接时,您需要使用 127.0.0.1 或 localhost
最重要的是,该错误表明您没有安装 Firebird 本机客户端。 FDB 驱动程序需要 fbclient.dll
(Windows) 或 libfbclients.so
(Linux)。您要么需要安装 Firebird 本机客户端,要么切换到 pyfirebirdsql,它是纯 Python 中的 Firebird 驱动程序(它在 Python 中实现了 Firebird 协议)。
我有一个 mydb.fdb
文件,如何将它加载到 docker 容器中,然后从 python 连接到它。我在 docker-compose 中执行以下操作:
version: '2'
services:
firebird:
image: jacobalberty/firebird
environment:
ISC_PASSWORD: pass
volumes:
- ./database:/databases
然后我做:
docker exec -it <container-id> bin/bash
而且我在容器的 /databases
文件夹中看到我的 .fdb
文件,但是当我在容器中执行命令时:
cd /usr/local/firebird/bin
./isql
SQL> CONNECT "/databases/mydb.FDB" user sysdba password masterkey;
我收到了:
Use of database at location /databases/mydb.FDB is not allowed by server configuration
而且我不明白如何通过 fdb python module 连接到这个数据库。我愿意:
import fdb
con = fdb.connect(
host='0.0.0.0',
port='3050',
database='mydb.FDB',
user='sysdba',
password='masterkey')
并收到:
raise Exception("The location of Firebird Client Library could not be determined.")
您的问题有两个不同的问题,以后请务必将它们作为单独的问题提出。
关于您的第一个问题,Firebird docker 图像的设置默认需要位置 /firebird/data
中的数据库,并明确配置 Firebird 以限制仅访问该位置。如果要使用不同的位置,则必须将环境变量 DBPATH
设置为正确的路径。另见图像的 issue 12, the Dockerfile and the build.sh。这个选项似乎没有记录;我已对该票发表评论。
关于你的第二个问题,它分为两个部分。一,不能用0.0.0.0来连接,那只是一个shorthand for "all ip addresses of this host",只能在监听连接的时候用,不能在连接的时候用。从机器 运行 docker.
连接时,您需要使用 127.0.0.1 或 localhost最重要的是,该错误表明您没有安装 Firebird 本机客户端。 FDB 驱动程序需要 fbclient.dll
(Windows) 或 libfbclients.so
(Linux)。您要么需要安装 Firebird 本机客户端,要么切换到 pyfirebirdsql,它是纯 Python 中的 Firebird 驱动程序(它在 Python 中实现了 Firebird 协议)。