Docker-compose with init default MemSql Database

Hello! How I can set the default DATABASE name when my Docker container is starting?
Here is my docker-compose.yml

version: '3.4'

services:
memsql-skywind:
build: ./database
hostname: memsql-skywind
container_name: memsql-skywind
ports:
- 3306:3306
- 8080:8080

And here is Dockerfile from database folder

FROM memsql/cluster-in-a-box

ENV LICENSE_KEY={LICENSE_KEY}

ENV START_AFTER_INIT=Y

COPY ./init.sql /docker-entrypoint-initdb.d/

And init.sql code is

CREATE DATABASE IF NOT EXISTS db;

In init.sql it specifies the db name as db. You can change the database name here. As you connect from your app / dashboard, you can similarly specify the new database name. This ensures the database exists as the container boots up, but I haven’t used the term default. Can you expand on the expected behavior you’d like to see here?

@robrich
I means, that if I run my configuration - the init.sql script is not runnig. And in this case I haven’t my DATABASE db at memsql cluster. So when my app trying to connect - I receiving the error saying there are no databse with such name as ‘db’.
So, the main question is how to run my init.sql with docker-compose to create the DATABASE at memsq cluster.

Ah, I see. Looking at the startup script, it appears init.sql should be at root. Try this:

COPY ./init.sql /

Thank you so much!
But it also needs to set the volume at docker-compose.

volumes:
- ./database/init.sql:/docker-entrypoint-initdb.d/

With all of this stuff, it working for me. Thanks!

1 Like