How to re-create container with latest image but old settings?

We have some containers that were started by hand on the CLI. Now I want to re-create them with the latest image for bug-fix and security reasons.

Is there a tool that can extract the settings (ports, volumes, environment, etc…) from the existing container and start a container with the latest image and the same old settings?

I am aware of watchtower, but I want to decide myself when and which container to update.

Maybe something like this?

https://stackoverflow.com/a/38077377/2584843

There are other solutions in the topic, but this looked more promising, however, it also sets the hostname which I wouldn’t as it is probably irrelevant when it is the default and a new container would have a new ID so also a new hostname. The good thing is that you can always create your own template based on the existing one.

Is it just for a temporary ssolution? Instead of relying on this for long, I would create a compose file or at least a script for the containers with all the necessary parameters

1 Like

This might be the missing piece in the puzzle:

It allows creating compose file from running containers. You can use it as foundation, and clean up the irrelevant parts it renders into the compose file.

If I built such a tool, I would take the current container configuration, remove everything that matches the defaults of the image, then remove everything that matches the defaults docker uses to create containers. which should leave you pretty much with a clean reverse engineered compose file.

1 Like