Is there available SQL (MySQL/PostgreSQL/SQL Server etc.) Docker container with records?
I know there are SQL containers on docker hub, but those are "empty" databases. I’m looking for a container where already installed schemas, tables etc and those tables are filled with records.
2
Answers
The way to migrate and seed databases with schemas and contents respectively varies from implementation to implementation. Both the Postgres and MySQL official docker containers allow you to mount a folder with .sql files as a volume to the container, and all the mounted sql will be run when the container first boots up. Here’s an article explaining how that works with the MySQL docker image:
https://onexlab-io.medium.com/docker-compose-mysql-database-seed-3bcbdfc51e8b
That being said, these methods are only useful for these docker container implementations. If you want to handle migrations and data seeding in a way that will scale to production, managed databases (e.g. RDS), you should look into database migration frameworks in your preferred language. Here’s a few popular ones:
You can see example of doing this for Postgres in https://github.com/Tornike-Skhulukhia/postgres-to-mongo-importer/blob/main/docker-compose.yml.
Important part here is /docker-entrypoint-initdb.d/ , where you can put .sql files and when container starts it will execute the sql code in them.
For more info on this feature look at "Initialization scripts" part here https://hub.docker.com/_/postgres