I am currently trying to set up surrealDB with a docker-compose-file for a new project.
When executing docker compose up --build
, I want to start surrealDB and then import a provided surql-file, so that the started db already has data to work with.
This is my docker-compose for the surrealDB container now:
version: '3'
services:
surrealdb:
env_file:
- .env
restart: always
entrypoint: /surreal
command: start --log trace --user root --pass root file:/data/database.db
image: surrealdb/surrealdb:latest
ports:
- 8000:8000
volumes:
- ./data:/data/
When looking for how to add several commands into one docker-compose I've found several solutions, including sh -c
, > [command] && [command]
and several others similar to both.
But none of them worked how I expected. The most common error war surrealDB not knowing the command (sh for example) or not executing the second command:
command: >
start --log trace --user root --pass root file://data/database.db &&
import --conn http://localhost:8000 --user root --pass root --ns test --db test data/database.surql
This executes the start command but the import never starts. It's nowhere to be found within the logs, no command, no error, but also no data.
So my question is:
What is the best way to start a surrealDB database and import a surql-file into this database from within a docker-compose-file?
And another question that I haven't researched yet: Will executing the import command always overwrite the initialized data within the database? I've worked with postgres before and there an init.sql-file was copied into the docker entrypoint directory and only executed if the database wasn't already built. Is there maybe a similar way for surrealDB?
Thanks alot for your help