How to commit files to a docker image that are in directories declared as volumes
The commit operation will not include any data contained in volumes mounted inside the container.
What does this mean in practice?
If you have, for example, a docker image containing any kind of data storage (in my case a container used for development and testing purposes of Sophora CMS server), where the volumes containing data are declared as docker volumes in the original image, it is not possible to create a new image (with your personal, project specific test data) using
But there is a way to put content into directories declared as volumes: Create a
Dockerfile that is
ADD ing this content. Of course, this means that you have to copy the content from your prepared container somwhere where your new
Dockerfile has access to.
FROM baseimage ADD /path/to/data /path/to/data/volume/directory/in/container
The resulting image will contain data in the directories, even if they are still declared as volumes.