Source:http://stackoverflow.com/questions/26734402/how-to-upgrade-docker-container-after-its-image-changed
question:
Let ' s say I have pulled the official mysql:5.6.21 image.
I have deployed this image by creating several Docker containers.
These containers have been running for some time until the MySQL 5.6.22 is released. The official image of mysql:5.6 gets updated with the "new release" but my containers still run 5.6.21.
How does I propagate the changes in the image (i.e. upgrade MySQL distro) to all my existing containers? What is the proper Docker way of doing this? Answer: 1.
After evaluating the answers and studying, the topic I d like to summarize.
The Docker way to upgrade containers seems:
application containers should not store application data. This is way you can replace the app container with its newer version in any time by executing something like this:
Docker pull MySQL
Docker stop My-mysql-container
Docker rm my-mysql-container
Docker Run--name= My-mysql-container--restart=always \
e mysql_root_password=mypwd-v/my/data/dir:/var/lib/mysql-d MySQL
can store data either on host (in Directory mounted as volume) or in Special Data-only container (s). Read more about it here, here, and here.
upgrading applications (eg. with yum/apt-get upgrade) within containersare considered to be a anti-pattern. Application containers are supposed to be immutable, which shall, guarantee reproducible. Some Official application images (mysql:5.6 in particular) are not even designed to Self-update (Apt-get upgrade won ' t wor k).
I ' d like to thank everybody who gave their answers and so we could the all different. 2.
I don ' t like mounting volumes as a-link to a host directory, so I-came up and a for upgrading Docker containers W ITH entirely Docker managed containers. Creating a new Docker container with--volumes-from <container> would give the new container with the updated images Shared ownership of Docker managed volumes.
Docker pull MySQL
Docker create--volumes-from my_mysql_container [...]--name my_mysql_container_tmp MySQL
By isn't immediately removing the original My_mysql_container yet, you have the ability to revert the known Container if the upgraded container doesn ' t have the right data, or fails a sanity test.
At this point, I'll usually run whatever backup scripts I have for the container to give myself a safety net into case Somet Hing Goes Wrong
Docker stop My_mysql_container
Docker start my_mysql_container_tmp
Now you are have the opportunity to make sure the data for your expect to being in the new container are there and run a sanity check.
Docker RM my_mysql_container
Docker Rename my_mysql_container_tmp My_mysql_container
The docker volumes'll stick around so long as any container are using them, so you can delete the original container safe Ly. Once The original container is removed, the new container can assume the namesake of the original to make everything as PR Etty as it is to begin.
The
There are two major advantages to using this pattern for upgrading Docker. Firstly, it eliminates the need to mount volumes to host directories from allowing to is volumes directly to Upgraded containers. Secondly, you are never in a position where there isn ' t a working docker; So if the upgrade fails, your can easily revert to how it is working before by spinning up the original Docker container a Gain.