0

Using Docker, initialising ArangoDB from Python

Tried different ways to authenticate, always getting "error: database is uninitialized and password option is not specified"

Not sure how to format / connect 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

'

Looking for a simple and robust way to connect to ArangoDB in a Docker container from Python. How can I then continue using ArangoDB Docker from Python without having to think about that it is running in a Docker container. IE

import dockerpy

then continuing to use only the dockerpy library

0

1 Answer 1

1

According to docker-py documentation, There is a parameter called environment which should takes care of the environment variables that should be passed inside the container while running it.

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

So you have to modify the script to the following:

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)

Then after executing it you can check the docker logs for the container which indicates that the container is up and running

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

Regarding command paramter it is meant to be used in case you need to override the original CMD of the image while running a container.

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.