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 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 do 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?
Here's what it looks like using
docker-compose
when building a customDockerfile
.docker build -t imagename:version .
This will store your new version locally.docker-compose down
docker-compose.yml
file to reflect the new image name you set at step 1.docker-compose up -d
. It will look locally for the image and use your upgraded one.-EDIT-
My steps above are more verbose than they need to be. I've optimized my workflow by including the
build: .
parameter to my docker-compose file. The steps looks this now:docker-compose build
docker-compose up -d
I didn't realize at the time, but docker-compose is smart enough to simply update my container to the new image with the one command, instead of having to bring it down first.
Taking from http://blog.stefanxo.com/2014/08/update-all-docker-images-at-once/
You can update all your existing images using the following command pipeline:
Consider for this answers:
app_schema
app_db
root123
How to update MySQL when storing application data inside the container
This is considered a bad practice, because if you lose the container, you will lose the data. Although it is a bad practice, here is a possible way to do it:
1) Do a database dump as SQL:
2) Update the image:
3) Update the container:
4) Restore the database dump:
How to update MySQL container using an external volume
Using an external volume is a better way of managing data, and it makes easier to update MySQL. Loosing the container will not lose any data. You can use docker-compose to facilitate managing multi-container Docker applications in a single host:
1) Create the
docker-compose.yml
file in order to manage your applications:2) Update MySQL (from the same folder as the
docker-compose.yml
file):Note: the last command above will update the MySQL image, recreate and start the container with the new image.
I would like to add that if you want to do this process automatically (download, stop and restart a new container with the same settings as described by @Yaroslav) you can use WatchTower. A program that auto updates your containers when they are changed https://github.com/v2tec/watchtower
Similar answer to above
After evaluating the answers and studying the topic I'd like to summarize.
The Docker way to upgrade containers seems to be the following:
Application containers should not store application data. This way you can replace app container with its newer version at any time by executing something like this:
You 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 containers is considered to be an anti-pattern. Application containers are supposed to be immutable, which shall guarantee reproducible behavior. Some official application images (mysql:5.6 in particular) are not even designed to self-update (apt-get upgrade won't work).
I'd like to thank everybody who gave their answers, so we could see all different approaches.