Home > Mobile >  Persistent setup of MariaDB in Docker container
Persistent setup of MariaDB in Docker container

Time:09-30

I am trying to setup MariaDB in a Docker container for CI/CD testing. However, the way I do it the DB does not exist when I log into the container.

Here's parts of my Dockerfile

FROM debian:stable-slim

RUN apt -y install mariadb-server mariadb-client
EXPOSE 3306
ADD ./DBShema.sql /db/DBShema.sql
RUN mysqld_safe \ 
    mysqladmin --silent --wait=30 ping \
    mysql < /db/DBShema.sql

Does not show my DB / tables.

MariaDB [(none)]> show databases;
 -------------------- 
| Database           |
 -------------------- 
| information_schema |
| mysql              |
| performance_schema |
 -------------------- 
3 rows in set (0.001 sec)

How should that go properly to make the piped DB info persistent?

CodePudding user response:

I think you are overcomplicating things. I do not see the point of starting from a plain Debian installation that requires you to install the RDBMS manually.

There are MariaDB images already made that you can use as a starting point for your CI images. Take the following Dockerfile as an example:

FROM mariadb:10.6.4-focal
COPY schema.sql /docker-entrypoint-initdb.d

This effectively copies over an sql script into the directory that is used to initialize the database on the first container start. This is mentioned in this portion of the documentation.

Once this is done the spun off container will contain all the changes included in the related sql file. I hope this is what you want.

  • Related