Upgrade Nextcloud on Docker
My simple approach.
This is my simple approach to upgrading Nextcloud running in a docker container. It isn't the official recommended approach, but this method has worked for me through numerous upgrades.
Depending on the release notes, I don't tend to upgrade every single release, so it isn't unusual for me to have a couple of hops to go through. Care should be taken in case there has been any backend changes (paticually in the DB) that may break your Nextcloud if you skip a version. So to go from 20 to 22, you will need to upgrade to 21 as a hop for example.
First things first, put your Nextcloud into maintenance mode, on my deployement this is done with the following command. You may been to change the values as appropriate to your deployment.
# $USER = your nextcloud user (typically www-data) # $CONTAINERNAME = your nextcloud container name # # docker exec -i $USER -it $CONTAINERNAME \ /usr/local/bin/php /var/www/html/occ maintenance:mode --on
Once Nextcloud is in maintenance mode, I simply backup the database using the following command.
# $CONTAINERDB = your nextcloud database container name # $SQLUSER = your root SQL user account name # $SQLPWD = your root SQL password # $SQLDB = your nextcloud database name # $SQLBACKUPFILE = your filename.sql to backup your DB to. # # docker exec $CONTAINERDB /usr/bin/mysqldump \ -u $SQLUSER \ --password=$SQLPWD \ $SQLDB > $SQLBACKUPFILE \ #
Finally, backup the data directory.
# $DATABACKUPFILE = the filename to save your data directory to. # $DATADIR = full path to your data directory # tar -zcvf $DATABACKUPFILE.tar.gz $DATADIR
Once we have our Nextcloud in maintenance mode, and we have backup up the DB and Data directory we can start the upgrade. I am currently running version 23.0.0, the latest version on dockerhub has the version 24.0.5 so I can simply hop to the latest docker image.
# $NEXTCLOUDCONTAINER = nextcloud container name # $NEXTCLOUD_DB_CONTAINER = nextcloud db container name docker stop $NEXTCLOUDCONTAINER docker rm $NEXTCLOUDCONTAINER docker pull nextcloud:latest # # then start your nextcloud container with # exactly the same config options as before # docker run <OPTIONS> -d $NEXTCLOUDCONTAINER
Finally, turn off maintenance mode.
# $USER = your nextcloud user (typically www-data) # $CONTAINERNAME = your nextcloud container name # # docker exec -i $USER -it $CONTAINERNAME \ /usr/local/bin/php /var/www/html/occ maintenance:mode --off
You may need to go into your Nextcloud admin panel and check for any Apps you have, there may be upgrades waiting for you. :)