Docker has evolved quite a lot in the past few months, from nameless containers to named ones, from little support of persistent storage to support of mounted end-points and self-generated volumes.
So what if you have a new version of your redis container? And you want to keep your data and still name it … say … redis ?
Docker comes with awesome features but also limitations that make the above a bit laborious:
So how to keep the same name and the same data? Use a temporary container! That does nothing but hold your data while you kill the old container and free its name!
# Consider the following details for your "old" container NAME=i_like_this_name_very_much_and_i_wanna_keep_it IMAGE=some/image CMD=some_command # Pull / Update your container's image docker pull $IMAGE # Start a temporary container that does .. nothing docker run -d -name temp_box -volumes-from $NAME ubuntu:latest /bin/bash # Stop and remove the original container docker stop $NAME docker rm $NAME # Start the new container with the same old name docker run -d -name $NAME -volumes-from temp_box $IMAGE $CMD
We hope you enjoyed this little tip; go ahead and suggest others!