Loading up a Docker database with data
Michael
Posted on September 6, 2018
We all need data.
Especially when running code against local environments that in Production would be running against a back end database. When I was building up some local Dockerized applications (Tomcat and MySQL) I wanted to have my UI showing some data.
This was partly to know things were up and running, since our main page makes a call against the Database to display some information on the initial page. Data that lives in the backend, or in this case the MySQL container. I thought about how I might have to add start up scripts, or maybe set up a MySQL database already loaded, but then I found about Docker's entrypoint initdb.d and that solved my problem easily.
COPY deployment/docker/mysql/very-small-db.sql /docker-entrypoint-initdb.d
This takes my database dump, which I made small so all it needs is my schema and maybe a couple of days worth of data, and initializes my database with it when I start up the container. This way I can fiddle with the dataset as I want and rebuild the container and then be on my way.
The great part about using tools is when you suddenly find a new feature, or way to use them.
Posted on September 6, 2018
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.