How to store and migrate data in a container?

I have a container that reads some data from a sensor.
I need to store the data in somewhere and then once the reading is done, migrate the container to another host with the data.
What is the best way to store data in a container so that I could move it together with the container ?
One possible option is that I store them in a XML file withing the container.
Another option is that I use a DB to store my data. (for example MongoDB). In this case, is it possible to migrate the data that is stored in the DB ?

I’d recommend doing this. It is exactly like any other setup where you have an application and it stores data in a database. If the application container is stateless, then it doesn’t care where it runs so long as it can reach the database. The database doesn’t have to be Docker-based (IMHO it’s very convenient for development and probably isn’t right in production).

This is probably the worst option: the file will be deleted when the container exits, and there’s not any way to move the former container’s contents to another place.

A related option that could work is to mount a volume into the container, and store the XML file there. It could be a host-system directory, in which case you’d have to physically copy the file to move across systems, or you could use a multi-host-capable Docker volume plugin, but I don’t have any recommendations for that.

If a database is an option, it’ll probably be most familiar to your sysadmins, most straightforward to setup, and most maintainable long-term.