简体   繁体   English

Python连接到firebird docker数据库

[英]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. 我有一个mydb.fdb文件,如何将其加载到docker容器中,然后从python连接到它。 I do the following in my docker-compose: 我在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: 我在容器中的/databases文件夹中看到我的.fdb文件,但是当我在容器内执行命令时:

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 服务器配置不允许在位置/databases/mydb.FDB使用数据库

And also I don't understand how to connect to this db via fdb python module . 而且我也不明白如何通过fdb python模块连接到这个数据库。 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.") 提升异常(“无法确定Firebird客户端库的位置。”)

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. 至于您的第一个问题,默认情况下Firebird泊坞窗映像的设置需要位置/firebird/data ,并明确配置Firebird以限制仅访问该位置。 If you want to use a different location, then you must set the environment variable DBPATH to the correct path. 如果要使用其他位置,则必须将环境变量DBPATH设置为正确的路径。 See also issue 12 , the Dockerfile and the build.sh of the image. 另请参见问题12Dockerfile和图像的build.sh 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. 一,你不能使用0.0.0.0来连接,这只是“这个主机的所有IP地址”的简写,它只能在监听连接时使用,而不能在连接时使用。 You will need to use 127.0.0.1 or localhost when connecting from the machine running docker. 从运行docker的机器连接时,您将需要使用127.0.0.1或localhost。

On top of that, the error suggests that you have no Firebird native client installed. 最重要的是,该错误表明您没有安装Firebird本机客户端。 The FDB driver requires fbclient.dll (Windows) or libfbclients.so (Linux). FDB驱动程序需要fbclient.dll (Windows)或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). 您需要安装Firebird本机客户端,或者切换到pythonbirdsql ,它是纯Python中的Firebird驱动程序(它在Python中实现Firebird协议)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM