EDDYMENS

Last updated 2024-01-07 06:01:29

Docker Image Created From Container Is Missing Changes (fix)

Docker image missing changes

Let's say you commit a Docker [↗] container to an image, but then whenever you run that image it's missing some of the changes from the container.

Chances are the container has volumes [↗] mounted to it.

Volumes allow changes or data to be stored outside of the container and in the case of creating images out of these containers the volume contents are not persisted.

Creating an image without volumes

You should create images without volumes if you want to capture all changes from containers:

This is more of a "pre" solution. You should have done this before creating your container to force it to persist all your changes. But we can work backward.

  • Create the original image from a Dockerfile without volumes:
    01: VOLUME /var/www/html 02: VOLUME /var/log/httpd 03: VOLUME /var/lib/mysql 04: VOLUME /var/log/mysql 05: VOLUME /etc/apache2

    If your Dockerfile contains the above for example, you might want to comment them out.

  • Start a container based on this image
  • Then you can use the Docker copy [↗] command to copy over the files you would like to persist from the old container (one with volumes) to your host and then into the new container(one without volumes).
  • You can now commit the new container into an image.

Here is another article you might like 😊 "Diary Of Insights: A Documentation Of My Discoveries"