So basically I want to start a dgraph on docker with some data already present in it(say admin login and password, or the dgraph schema and so on) but I couldn’t create a Dockerfile to handle that. Could you help me with that?
That’s not possible as far I got from your question.
What you could do is run a script that updates the schema and seeds some data to the Docker container when it boots. What is your use-case?
The idea is to build a docker image with admin user and password and its privileges, with predefined schema already in the database
Well, that is possible. You can run Dgraph during a Docker Build step and run a script to load all those configs you need. What I do not recommend is create an image with data loaded. This will create a big image, that’s a bad practice. As the image will have that dataset written in stone(image), and also occupying space with big images.
It seems like I have confused everybody. I can simplify.
Basically I need help with the dockerfile.
I have one file: A schema file: That defines the types.
# QUERY TYPE: ALTER
# Define Types
type Store {
store !
class
geolocation
}
type Product {
product !
stores
}
# Define Directives and index
store: String @index(trigram) .
product: String @index(term,fulltext) .
class: uid .
stores: [uid] @reverse .
geolocation: geo .
Thanks for the advice @MichelDiz could anyone help me with the dockerfile?
FROM dgraph
ADD ./Schema ./
# How to add the Schema????
RUN curl -X POST localhost:8080/alter < ./Schema
Something like this
curl "localhost:8080/alter" --silent --request POST \
--data-binary "@path/to/Schema"
Yeah but how to I run dgraph at the same time??? I can’t run the dgraph and have it do the alter at the same time, that’s the problem. I need to find a way to alter the schema without running the dgraph or run it it the background in dockerfile.
dockerfile should look something like this:
FROM dgraph
ADD ./Schema ./
RUN #(here dgraph should run in background)
RUN curl "localhost:8080/alter" --silent --request POST /
--data-binary "@path/to/Schema"
in a single line you gonna use some command line tricks. Something like
RUN dgraph zero & dgraph alpha & \
bash waitforit.sh
You have or to create the whole process in that multiline or create a script file(waitforit.sh) to run the rest of the process
Finally! thanks a lot . I will try that. But it didn’t have to be all in one line. I will inform you about the results.
By the way how to drop all data with curl command? And how to deploy the container with CMD??? I haven’t figure that out
curl -X POST localhost:8080/alter -d '{"drop_op": "DATA"}'
EDIT:
What hosting platform are you deploying to? With render.com you just add a custom CMD argument in the deployment settings:
Sorry for late reply and huge thanks for support, actually the answer to my second question was
CMD dgraph zero & dgraph alpha
And thanks for answering the first question. I appreciate it.