arangodb / arangodb-docker

Docker container for ArangoDB
Apache License 2.0
107 stars 32 forks source link

Not connected when running init shell scripts #69

Open mhaagens opened 5 years ago

mhaagens commented 5 years ago

I'm trying to create a new database on init, but I'm only getting errors saying it's not connected.

Error:

ERROR JavaScript exception in file '/usr/share/arangodb3/js/client/modules/@arangodb/arango-database.js' at 388,40: ArangoError 2001: not connected\n!  var requestResult = this._connection.POST(this._collectionurl() + urlAddon, body);\n!                                       ^\nstacktrace: ArangoError: not connected\n    at Proxy.ArangoDatabase._create (/usr/share/arangodb3/js/client/modules/@arangodb/arango-database.js:388:40)\n    at (command-line):1:4\n

docker-compose.yml

version: "3"
services:
  arangodb:
    build:
      context: ./docker/arangodb
      dockerfile: Dockerfile
    environment:
      - ARANGO_STORAGE_ENGINE=rocksdb
      - ARANGO_ROOT_PASSWORD=password
      - ARANGO_DB="test"
      - ARANGO_DB_USER="test"
      - ARANGO_DB_PASSWORD="test"
    volumes:
      - ./docker/arangodb/data:/var/lib/arangodb3
    ports:
      - 8529:8529

./docker/arangodb/Dockerfile

FROM arangodb/arangodb:latest
COPY ./config/init/ /docker-entrypoint-initdb.d/
RUN chmod -R 755 /docker-entrypoint-initdb.d/

/docker-entrypoint-initdb.d/001-create-database.sh

#!/bin/bash
/usr/bin/arangosh \
    --server.endpoint=unix:///tmp/arangodb-tmp.sock \
    --server.password ${ARANGO_ROOT_PASSWORD} \
    --javascript.execute-string "db._create('testcollection_from_sh_test');" \
    --javascript.execute-string "db._createDatabase(${ARANGO_DB_NAME}, null, [{username: ${ARANGO_DB_USER}, password: ${ARANGO_DB_PASSWORD}]);"
dothebart commented 5 years ago

Hi, by default the arangodb docker container doesn't bind unix domain sockets. You can however make it do so by specifying it should do (this example chooses to disable authentification for simplicity):

docker run -it -e ARANGO_NO_AUTH=1 --server.endpoint unix:///tmp/arangodb-tmp.sock

then your arangosh should be able to connect to that unix domain socket.

A nice addon is, that you could share that socket with your host if you mount the filesystem the socket is created on into the container using -v:

docker run -v /var/run/arangodb/:/tmp/ -it -e ARANGO_NO_AUTH=1 --server.endpoint unix:///tmp/arangodb-tmp.sock

you could then connect it from the host like that:

/usr/bin/arangosh --server.endpoint unix:///var/run/arangodb/arangodb-tmp.sock