Skip to content
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

Cockpit Docker fails to restore data from MongoDB after docker rebuild #799

Closed
woutervddn opened this issue Jul 3, 2018 · 4 comments
Closed

Comments

@woutervddn
Copy link

Yesterday I posted this on the Discourse: https://discourse.getcockpit.com/t/bug-or-intended-behavior-mongodb-cockpit-docker-fails-to-restore-data-after-docker-restart/107
I'm since then certain that this is a bug.

I spawned a cockpit instance using MongoDB on a Dokku instance (self hosted heroku). The application connects and I can create a singleton.

When I rebuild the docker container using the Dokku commandline the singleton is gone. However, during the creation process of the exact same singleton (name, label, description) with the exact same fields, the form fields are prefilled with the original content.

It is as if redis, mongo or (cockpit itself?) fails to read the singleton from the DB.

I also noticed this behavior on a normal docker image (not running on Dokku).

Is there a way to force refresh the cache? Or does the root of this problem reside somewhere else?

@jongirard
Copy link

Also having this problem with Docker and MongoDB with the use of volumes. Unable to use docker if the data storage of collections doesn't persist as it should.

@woutervddn
Copy link
Author

Ah, I managed to solve this... :)

So apparently it works like this: Whenever you create a collection, singleton,.... It generates a file that hosts the 'model' of that type. That file is a PHP file that is stored in 'storage'. Furthermore, images and other uploaded media/files are stored in 'storage' as well.

It is the content of the entries that is saved in MongoDB. That is why it's possible to recreate a previously existing model in a fresh docker container and suddenly see your entries pop up again.

All in all the solution was really simple: both the MongoDB as well as the storage need to be valid External sources. For MongoDB that means setting up environment variables: https://getcockpit.com/documentation/reference/docker

For storage, that means setting up a persistent Docker volume.

Lastly, you need to add a separate config file to the docker image in order to enable the usage of the MongoDB environment variables. The changes to the documentation to include this config.php page are already made, but not online yet.

You can find a working config example here: https://github.com/woutervddn/cockpit-docs/blob/b52ec6d63c0627b3c27180df109f93e0077927c3/reference/docker/index.md

@aheinze aheinze closed this as completed Aug 14, 2019
@AKApumkin
Copy link

For anyone looking for simple docker-compose that you can run without having to write the Dockerfile configs yourself -> https://github.com/AKApumkin/cockpit-persistent

@sidbenac
Copy link

sidbenac commented Nov 5, 2020

why don't you store all Json in mongodb when configured ( data and models ), cockpit container in production must stay away from data it only needs to hold code. it is painful that everytime we rebuild the docker container we lose all the collection models that are physically stored on docker or volume.
I am actually using cockpit in production with gcloud as static storage, but everytime I rebuild the docker container a lose all models. is there a work around without creating volumes ?

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

5 participants