Surreal DB does not start on alpine container,
use ubuntu container instead
1. Create an Ubuntu container
docker run -d -p 17000:8000 --name ub_surreal ubuntu tail -f /dev/null
2. Exec the container in it mode
docker exec -it -u 0 ub_surreal sh
3. Update apt ( this is required to install curl)
apt update
This will take some time may be 2-3 mins because apt coming with container is bare minimum
4. Install curl
apt install curl
Press 'Y' when prompted
5.
curl -sSf https://install.surrealdb.com | sh
This will install surreal db.
6. Start surreal db
surreal start --log debug --user root --pass root memory
This will start surreal and keep it started.
7. Open another command prompt and again open the same container with EXEC command:
docker exec -it -u 0 ub_surreal sh
8. Now you can give the command and use surrealdb.
For example you can give the following command:
curl --request POST --header "Accept: application/json" --header "NS: test" --header "DB:test" --user "root:root" --data "INFO FOR DB;" http://localhost:8000/sql
you should get a response like
[{"time" : "47.432ms" , "status" : "OK" , "result" : { "d1" : {} , "dt" : {}, "sc" : {} , "tb" : {}}}]
https://www.freecodecamp.org/news/how-to-use-surrealdb-with-fresh-framework/
========================================================================
Start Surreal using dockerfile
1. Execute the following dockerfile:
========================================================================
Dockerfile
========================================================================
FROM ubuntu
RUN apt update
RUN apt-get install -y curl
RUN curl -sSf https://install.surrealdb.com | sh
CMD surreal start --log debug --user root --pass root memory
========================================================================
NOTE the use of apt and apt-get : apt-get has more features than apt,
i.e. apt is a stripped down vesrion of apt-get
2. Build the above docker file:
docker build -t surreal-image .
NOTE : image name must be all smalls.
3. Run it:
docker run -p 17000:8000 -d --name surrealdb surreal-image
4. Execute it:
docker exec -it -u 0 surrealdb sh
5. Execute the following command on shell:
surreal sql -c http://localhost:8000
You will be presented with surreal sql prompt. ( >)
>info for db <Enter>
[{"time" : "23.728ms" , "status" : "ERR" , "detail" : "Specify a namespace to use"}]
6. Now exit sql shell by pressing ctrl + C and enter the following command:
surreal sql -c http://localhost:8000 --ns test --db test
>info for db
[{"time" : "50.292ms" , "status" : "OK" , "result" : { "d1" : {} , "dt" : {}, "sc" : {} , "tb" : {}}}]
> create account set name = 'test' , created_at = time::now()
> CREATE author:john SET name.first = 'John' , name.last = 'Adams' , name.full = string::join(' ', name.first, name.last) , age = 29, admin = true, signup_at = time::now();
> select * from author, account;
No comments:
Post a Comment