A custom database image comes to mind. Generate the script once, and copy that into your own database image. Something like:
COPY initdb.sql docker-entrypoint-initdb.d/initdb.sql
Build and tag using
docker build -t <your-docker-id>/guacamole-mariadb ., push to your own Docker Hub repository using
docker push <your-docker-id>/guacamole-mariadb, and use that image in the Compose file.
But, the above still needs you to generate the
initdb.sql file one time. Now, the documentation says:
Alternatively, you can use the SQL scripts included with the database authentication.
That’s quite vague. But on the Docker Hub repo it says:
Alternatively, you can use the SQL scripts included with guacamole-auth-jdbc.
If those are somehow usable then you could
ADD them from GitHub directly:
ADD https://raw.githubusercontent.com/apache/guacamole-client/0.9.10-incubating/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/001-create-schema.sql /docker-entrypoint-initdb.d/
ADD https://raw.githubusercontent.com/apache/guacamole-client/0.9.10-incubating/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/schema/002-create-admin-user.sql /docker-entrypoint-initdb.d/
I’ve no idea if MariaDB would pick up the two scripts
002-create-admin-user.sql. But the
directory in the directory name
docker-entrypoint-initdb.d suggests it does. Let us know! (Aside: the file dates will be set to Jan 1, 1970.)
And are these indeed the same files? Peeking into
/opt/guacamole/bin/initdb.sh tells you more. The relevant part seems to be:
docker run --rm guacamole/guacamole cat /opt/guacamole/bin/initdb.sh
So, it concatenates all
.sql files into a single file. A quick look suggests those are the same files indeed:
docker run --rm guacamole/guacamole /bin/sh -c "ls -l /opt/guacamole/mysql/schema/*.sql"
-rw-r--r-- 1 root root 20174 Oct 17 00:52 /opt/guacamole/mysql/schema/001-create-schema.sql
-rw-r--r-- 1 root root 2876 Oct 17 00:52 /opt/guacamole/mysql/schema/002-create-admin-user.sql
initdb.sh uses those files (but still not sure if MariaDB would pick up multiple files in that folder; let us know!), I’d prefer:
COPY --from=guacamole/guacamole /opt/guacamole/mysql/schema/*.sql /docker-entrypoint-initdb.d/
Alternatively, rather than creating your own MariaDB image, you may be able to share the initialization volume between Guacamole and MariaDB. For Guacamole map it to
/opt/guacamole/mysql/schema/ and for MariaDB to
/docker-entrypoint-initdb.d/. But that would very much rely on the startup order, to ensure Docker copies the files from Guacamole into the empty volume on first start. Sounds unreliable, especially as you actually want to start MariaDB first.
Or make Guacamole create the tables itself, rather than relying on the MariaDB initialization. Other users will be happy with a merge request to achieve that!
Aside: I wonder what happens if Guacamole is updated. Would it work with an outdated
initdb.sql? Would it change the database schema when needed?