MySQL Docker container is not saving data to new image MySQL Docker container is not saving data to new image docker docker

MySQL Docker container is not saving data to new image


As another answer and you have stated volumes cannot be committed and child containers do in fact inherit volume definitions from parents. Hence any changes to the volume will be discarded. I would like to add data such as mysql database files should always be in volumes for several reasons and you should not be trying to commit it into your image.

  1. If you have to migrate containers there is no easy way to extract data from containers if its not in a volume.
  2. If you want to start multiple containers that share data you have to have data in a volume.
  3. If you want to change your container definition with say new volumes or ports you have to delete and recreate it. If you have data in the container you will loose it. (See this question for an example of this case.)
  4. The union file system is slower than normal file systems which will slow down your application or database.

So what should you do instead?

  1. Use a data only container that can be linked with any instance of the service container. Then you can use volumes-from to get your data into the service container.
  2. Use a host mounted volume so that you can restart containers and mount the same location into new containers.


You are probably better off rolling your own mysql. That way there are no surprises, no hidden "magic" in there.

If you look at an example dockerfile for mysql core, you can see the VOLUME declaration for /var/lib/mysql.

Docs on docker volumes.

Data volumes

A data volume is a specially-designated directory within one or more containers that bypasses the Union File System to provide several useful features for persistent or shared data:

  • Data volumes can be shared and reused between containers
  • Changes to a data volume are made directly
  • Changes to a data volume will not be included when you update an image
  • Volumes persist until no containers use them