The version upgrade is divided into two parts, one is the upgrade of the database service, and the other is the upgrade of other services.
1. Of course, the first thing to do is to judge whether you need to upgrade. I didn't think of a better way. I judged based on the tag of the docker image. The tag can be used as the version number. By comparing the tag of the installed image and the version number to be installed Compare to see if you need to upgrade.
(1) Query the tag of an image
declare tag=$(docker images | grep 'image name' | awk {'print $2'})
docker images | grep 'image name' | awk {'print $2'} means to find the image that contains a certain string in the docker images list, and return the second column of the list, the tag column.
root@greenvm-w14014v2:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE sebp/elk latest ac9f80b1eba4 3 days ago 1.15GB ubuntu 16.04 c9d990395902 6 days ago 113MB fluent/fluentd latest 19e4a20a16e2 7 days ago 38.2MB tomcat latest 33e02377a00f 7 days ago 554MB nginx latest b175e7467d66 8 days ago 109MB
(2) Compare the size of the version number
if [ -z "${tag}" ]; then If #tag is empty, it means that docker is not installed, and you need to go through the installation process. elif [[ "${tag}" < "latest version" ]]; then #Go to the upgrade process be
2. The upgrade of other services is relatively simple. You only need to destroy the container and image and rebuild it.
(1) Destroy the container and execute it in the directory where docker-compose.yml is located:
docker-compose down
(2) Delete the mirror
docker rmi -f $(docker images | grep athena | awk {'print $3'})
(3) Rebuild the image and run the container, execute it in the directory where docker-compose.yml is located
docker-compose up -d
3. The upgrade of the database, I think about it myself, I don't know if there is a better plan.
step:
(1) Copy the upgrade script to the mysql container
(2) Execute the upgrade script
Let's talk about it separately:
(1) Copy the upgrade script to the mysql container
docker cp file path to be copied container name: to be copied to the corresponding path in the container
In this example:
docker cp upgrade.sql mysql-server:/usr/local/work docker cp upgrade.sh mysql-server:/usr/local/work
(2) Execute the upgrade script
Execute in the docker-compose.yml file directory:
docker-compose exec container name command
In this example:
docker-compose exec mysql-server bash /usr/local/work/upgrade.sh
upgrade.sh:
mysql -uroot -p$MYSQL_ROOT_PASSWORD << EOF source /usr/local/work/upgrade.sql EOF
ps:
Since the data of the mysql container database is placed in the host file system, the destruction or creation of the mysql container or even the reconstruction of the mysql image will not affect the data, and the database can still be used normally after the container is re-run.