De ehhez egy másik konténer való. Van egy konténered, az alkalmazás, ami használja a db-t, és egy másik konténered, ami maga a db.
Szépen elkülöníted a felelősségi köröket, nem keverednek a konténerek között.
Használd például a hivatalos mariadb konténert.
https://hub.docker.com/_/mariadb/
Initializing a fresh instance
When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions
.sh,.sql,.sql.gz,.sql.xzand.sql.zstthat are found in/docker-entrypoint-initdb.d. Files will be executed in alphabetical order..shfiles without file execute permission are sourced rather than executed. You can easily populate yourmariadbservices by mounting a SQL dump into that directory and provide custom images with contributed data. SQL files will be imported by default to the database specified by theMARIADB_DATABASE/MYSQL_DATABASEvariable.
Azaz van egy maradb konténered, a neki megfelelő init scripttel a /docker-entrypoint-initdb.d mappa alatt. Ehhez persze a legcélszerűbb egy custom image, ami a mariadb image-ből ered, és ADD-dal vagy COPY-val hozzáadod az init scriptedet. Ezután lesz egy image-d, amit ha elindítasz üresen, létrehozza azt az adatbázist, amit szeretnél. Ezután már csatlakozhatsz az alkalmazásból hozzá.