I am able to pull the YB image and run a container, able to do YSQLSH and execute Create DB, Create Schema and query tables, its all good. But I do have a requirement to run all these,
Create the DB
Create the sample Schemas
Insert the data into those sample table.
in a script file. So that, when my developer pull my image and run a container, which should pull my script file during the container creation, it will get the DB and Schema ready for them. So that they do not have to run multiple commands in it.
I was able to login to this DB directly this way.
docker container exec -it imgyb1cont1 /home/yugabyte/bin/ysqlsh “yb_demo”
But again, to do this, the DB should exist before. which will not happen unless I issue CREATE DATABASE COMMAND.
Please help.
Also I am thinking to put together the YugabyteDB Quick start for macOS | YugabyteDB Docs the SQL Queries in a file such as ybinit.sql and want to call that when creating a container. But how can I get directly connected to ysqlsh and run the sql file?
Thank you Dorian. I actually found another way to do this.
Copied by ysqlscript.sql to bin folder of YB and then executed this. It actually has worked though.
My ysqlscript.sql has the below code.
CREATE DATABASE yb_demo;
\c yb_demo;
\i share/schema.sql;
\i share/products.sql;
\i share/users.sql;
\i share/orders.sql;
\i share/reviews.sql;
However, I like your line of code as well.
But is that possible to combine both in one line as below
docker exec -it yb1 /home/yugabyte/bin/ysqlsh -c ‘create database yb_demo;’ -f share/schema.sql
When I execute, it creates the DB successfully but then when it runs the schema.sql it error out saying the relation already exists. But actually it is not.
Dorian. I understand those schema.sql, products.sql are all by default available in there and so I can create those by calling those sql script files. But if I want to copy my own table structure, then I can put those into a SQL and use it? How do I do that?
FROM yugabytedb/yugabyte:latest
RUN uname -a
RUN ls -l
ENTRYPOINT [“/home/yugabyte/bin/ysqlsh”, “-c ‘create database yb_demo;’”]
This is supposed to create the yb_demo DB when I run a container. But it does not. The image gets created successfully as well, the container runs good as well, just the DB is not getting created. Please help me what I am doing wrong.
And when I have the entrypoint that way mentioned above, I am getting this error
ysqlsh: could not connect to server: Connection refused
Is the server running on host “localhost” (127.0.0.1) and accepting
could not connect to server: Cannot assign requested address
Is the server running on host “localhost” (::1) and accepting
TCP/IP connections on port 5433?
I even tried EXPOSE 7000 9000 5433 9042 on my dockerfile. no luck
Please see the output above. When I just run the above, one output shows the ysqlscript.sql and cont.sh in its output, But the other one does not show that. Any reason why? Thank you