Skip to content

How to Initialize container with fixture data? #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
k0pernikus opened this issue Feb 19, 2018 · 1 comment
Closed

How to Initialize container with fixture data? #247

k0pernikus opened this issue Feb 19, 2018 · 1 comment

Comments

@k0pernikus
Copy link

I have written a so question about this, yet I ponder it fits more here.

As a developer setting up a development stack using docker-compose, I like to have the option to setup a mongo db with fixture data, similar as to the mariadb image works:

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 and .sql.gz that are
found in /docker-entrypoint-initdb.d. Files will be executed in
alphabetical order. 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 MYSQL_DATABASE variable.

It seems that currently I have to either query the database manually after it was created, meaning I have to either point out some manual steps in the Readme.md. (Currently, I require a developer to have a mongo-client installed, in order to fire some queries, which will be copy-pasted.)

I want to automate that process so that docker-compose or a custom dockerfile takes care about the initalization.

Is there a current best practice on how to achieve that? Otherwise, please kindly treat this as a feature request :)

@yosifkit
Copy link
Member

The same functionality now exists in the MongoDb image for Bash and JavaScript files:

for f in /docker-entrypoint-initdb.d/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.js) echo "$0: running $f"; "${mongo[@]}" "$MONGO_INITDB_DATABASE" "$f"; echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done

We are just working on documenting it: docker-library/docs#1127. It was previously considered unstable, so we hadn't documented it. Hopefully we can get some docs up soon.

Related to #189.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants