ArangoDBs python docker

问题描述 投票:0回答:1

使用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

进口码头py

然后继续只使用dockerpy库

python docker arangodb
1个回答
1
投票

根据docker-py documentation,有一个名为environment的参数,它应该处理在运行它时应该在容器内传递的环境变量。

environment(dict或list) - 要在容器内设置的环境变量,作为字典或字符串列表,格式为[“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

关于qazxsw poi参数,它用于在运行容器时需要覆盖图像的原始command的情况。

command(str或list) - 要在容器中运行的命令。

© www.soinside.com 2019 - 2024. All rights reserved.