( persicsb | 2022. 12. 04., v – 20:45 )

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.xz and .sql.zst that are found in /docker-entrypoint-initdb.d. Files will be executed in alphabetical order. .sh files without file execute permission are sourced rather than executed. You can easily populate your mariadb services 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 the MARIADB_DATABASE / MYSQL_DATABASE variable.

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á.