ArangoDBs python公司

2024-05-16 06:54:35 发布

您现在位置:Python中文网/ 问答频道 /正文

使用Docker,从Python初始化ArangoDB

尝试了不同的身份验证方法,始终得到“错误:数据库未初始化,未指定密码选项”

不确定如何格式化/连接ArangoDB

import docker
client=docker.from_env()
img=client.images.pull("arangodb:latest")
[31]:

arangocommand="-e ARANGO_RANDOM_ROOT_PASSWORD=1"
​
db=client.containers.run(img,command=arangocommand)

---------------------------------------------------------------------------
ContainerError                            Traceback (most recent call last)
<ipython-input-31-c5425f08f615> in <module>
      1 arangocommand="-e ARANGO_RANDOM_ROOT_PASSWORD=1"
      2 
----> 3 db=client.containers.run(img,command=arangocommand)

~/anaconda3/envs/dockerdb/lib/python3.7/site-packages/docker/models/containers.py in run(self, image, command, stdout, stderr, remove, **kwargs)
    793         if exit_status != 0:
    794             raise ContainerError(
--> 795                 container, exit_status, command, image, out
    796             )
    797 

ContainerError: Command '-e ARANGO_RANDOM_ROOT_PASSWORD=1' in image 'sha256:d41deeeb6f1189a07e3e567bd104c82b53350b67eaadbe044fae9c1158cd8c1c' returned non-zero exit status 1: b'error: database is uninitialized and password option is not specified \n  You need to specify one of ARANGO_ROOT_PASSWORD, ARANGO_NO_AUTH and ARANGO_RANDOM_ROOT_PASSWORD\n

'

在Python的Docker容器中寻找连接到ArangoDB的简单而健壮的方法。然后如何继续使用Python中的ArangoDB Docker,而不必考虑它是在Docker容器中运行的。IE公司

import dockerpy

然后继续只使用dockerpy库


Tags: dockerruninclientimgrandomrootpassword
1条回答
网友
1楼 · 发布于 2024-05-16 06:54:35

根据docker-pydocumentation,有一个名为environment的参数,它应该负责在运行容器时在容器内部传递的环境变量。你知道吗

environment (dict or list) – Environment variables to set inside the container, as a dictionary or a list of strings in the format ["SOMEVARIABLE=xxx"].

因此,您必须将脚本修改为以下内容:

import docker

client=docker.from_env()

img=client.images.pull("arangodb:latest")
variables=["ARANGO_RANDOM_ROOT_PASSWORD=1"]
db=client.containers.run(img,environment=variables)

然后在执行它之后,您可以检查容器的docker日志,这表明容器已启动并正在运行

automatically choosing storage engine
===========================================
GENERATED ROOT PASSWORD: XXXXXXXXXXXXXXXX
===========================================
...
2019-02-19T06:22:31Z [1] INFO using storage engine rocksdb
2019-02-19T06:22:31Z [1] INFO {cluster} Starting up with role SINGLE
...
2019-02-19T06:22:31Z [1] INFO {authentication} Authentication is turned on (system only), authentication for unix sockets is turned on
2019-02-19T06:22:32Z [1] INFO using endpoint 'http+tcp://0.0.0.0:8529' for non-encrypted requests

关于command参数,它用于在运行容器时需要重写映像的原始CMD的情况。你知道吗

command (str or list) – The command to run in the container.

相关问题 更多 >