Search code examples
imagedockercontainers

Update the base image of a committed docker container


I have just committed and saved a MySQL container to an image. This MySQL container was created using Portainer, a long time ago, with the main upstream MySQL image through the Portainer web interface making some mouse clicks.

The point with the image was to take it to another server with all the history, metadata and such. I saved also the volume with MySQL data.

I managed to replicate perfectly the same environment on the new server.

But now I'm a bit concerned as I can not find a way to update the "base" MySQl image.

To be clear, I did not build any image with any Dockerfile. The process was exactly as I stated before, through Portainer using MySQL mainstream image from Docker Hub.

So, is there any way to update the MySQL part of my container? I believe there should be, because of all that layers Docker philosophy.

Thanks for your time and help


Solution

  • You can't update the base image underneath an existing image, no matter how you created it. You need to start over from the updated base image and re-run whatever commands you originally ran to create the image. The standard docker build system will do this all for you, given a straightforward text description of what image you start FROM and what commands you need to RUN.

    In the particular case of the Docker Hub database images, there's actually fairly little you can do with a derived image. These images are generally set up so that it's impossible to create a derived image with preloaded data; data is always in a volume, possibly an anonymous volume that gets automatically created, and that can't be committed. You can add files to /docker-entrypoint-initdb.d that will be executed the first time the database starts up, but once you have data in a volume, these won't be considered.

    You might try running the volume you have against an unmodified current mysql image:

    docker run -d -p 3306:3306 -v mysql_data:/var/lib/mysql mysql:8
    

    If you do need to rebuild the custom image, I'd strongly encourage you to do it by writing a Dockerfile to regenerate the image, and check that into source control. Then when you do need to update the base image (security issues happen!) you can just re-run docker build. Avoid docker commit, since it will lead to an unreproducible image and exactly the sort f question you're asking.