Adding data directly to the container image works very well for applications that you do not want to change while the applications are running. Your application code usually falls into this category. For tasks that will be updating data regularly, it is better to put the data on a volume. Volumes also provide a measure of data persistence since they stick around even after a container is removed.
Volumes are one of the keys to orchestration. Putting container data in an external volume helps to facilitate container updates and running containers across multiple hosts. Using networked, shared storage is covered in Chapter 3 , Cluster Building Blocks - Registry, Overlay Networks, and Shared Storage.
Let's go back to the web database example. The way it is configured at the beginning of the chapter, the database is created every time the application starts and destroyed when the application stops. That works for an example, but it is not very practical in real...