How to upgrade docker container after its image changed
2017-01-27 03:15
447 查看
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 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?
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.
By not immediately removing the original
you have the ability to revert back to the known working 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 in case something goes wrong
Now you have the opportunity to make sure the data you expect to be in the new container is there and run a sanity check.
The docker volumes will stick around so long as any container is using them, so you can delete the original container safely. Once the original container is removed, the new container can assume the namesake of the original to make everything as
pretty as it was to begin.
There are two major advantages to using this pattern for upgrading docker containers. Firstly, it eliminates the need to mount volumes to host directories by allowing volumes to be directly transferred to an upgraded containers. Secondly, you are
never in a position where there isn't a working docker container; so if the upgrade fails, you can easily revert to how it was working before by spinning up the original docker container again.
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 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?
Answer:
1.
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:
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
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.
2.
I don't like mounting volumes as a link to a host directory, so I came up with a pattern for upgrading docker containers with entirely docker managed containers. Creating a new docker container with--volumes-from <container>will 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 not immediately removing the original
my_mysql_containeryet,
you have the ability to revert back to the known working 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 in case something goes wrong
docker stop my_mysql_container docker start my_mysql_container_tmp
Now you have the opportunity to make sure the data you expect to be in the new container is there and run a sanity check.
docker rm my_mysql_container docker rename my_mysql_container_tmp my_mysql_container
The docker volumes will stick around so long as any container is using them, so you can delete the original container safely. Once the original container is removed, the new container can assume the namesake of the original to make everything as
pretty as it was to begin.
There are two major advantages to using this pattern for upgrading docker containers. Firstly, it eliminates the need to mount volumes to host directories by allowing volumes to be directly transferred to an upgraded containers. Secondly, you are
never in a position where there isn't a working docker container; so if the upgrade fails, you can easily revert to how it was working before by spinning up the original docker container again.
相关文章推荐
- How to update Docker image to maintain your containers secure
- How to tile small texture image onto page as its background?
- (OK) NS-3—LXC-(Docker)—MANET——HOWTO Use Linux Containers to set up virtual networks
- How to scroll an image, if it does not fit in the display
- how to create image file and format it
- How to configure locales to Unicode in a Docker Ubuntu 14.04 container?
- Docker - How to create a custom database from docker mysql image
- How to list all tags of a docker image
- how-to upgrade all local docker images
- How to tile small texture image onto page as its background
- How to upgrade Image by jigdo
- How to solve boot problems with Ubuntu after kernel upgrade
- Docker - How to Connect to a MySQL Running Container Using MySQL Command Line Client
- (全英文)How to install and run a simple Asp.Net 5 Application in a Docker Container
- How to Interactively Create a Docker Container
- How to Get Code into a Docker Container
- [linux]How to set PATH in shell script, and keep it avaiable even after it exits
- How to get xen whole-machine dump image and analyse it prepair
- NDIS Debugging Tips 0x01 how ndis miniport connect its ISR to system ?
- DSL(Domain Specific language): How to get it