I am running SonarQube with a Postgres and an nginx container on a remote VM via docker-compose file. Initially, I was using sonarqube:latest. I took the backup of my postgres and nginx data using a contemporary container -
docker run --rm -v sonar_sonarqube_data:/source -v $(pwd)/backup:/backup ubuntu tar -czvf /backup/sonarqube_data.tar.gz /source
docker run --rm -v sonar_sonarqube_extensions:/source -v $(pwd)/backup:/backup ubuntu tar -czvf /backup/sonarqube_extensions.tar.gz /source
docker run --rm -v sonar_sonarqube_logs:/source -v $(pwd)/backup:/backup ubuntu tar -czvf /backup/sonarqube_logs.tar.gz /source
docker run --rm -v sonar_postgresql:/source -v $(pwd)/backup:/backup ubuntu tar -czvf /backup/postgresql.tar.gz /source
Then I changed the image version to 25.2.0.102705-community and rebuilt the containers (docker compose down and docker compose up -d).
I lost all my projects. I had to set them up manually again. Here is the docker-compose.yml which I’m using -
services:
sonarqube:
image: sonarqube:25.2.0.102705-community
container_name: sonarqube
ports:
- "9000:9000"
- "9092:9092"
environment:
- SONARQUBE_JDBC_USERNAME=brothermayihavesomeoats
- SONARQUBE_JDBC_PASSWORD=brothermayihavesomeoats
- SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonar
networks:
- sonarnet
volumes:
- sonarqube_data:/opt/sonarqube/data
- sonarqube_extensions:/opt/sonarqube/extensions
- sonarqube_logs:/opt/sonarqube/logs
db:
image: postgres:latest
container_name: postgres
environment:
- POSTGRES_USER=brothermayihavesomeoats
- POSTGRES_PASSWORD=brothermayihavesomeoats
networks:
- sonarnet
volumes:
- postgresql:/var/lib/postgresql/data
As you can see, I have persisting volumes. But when I changed the SonarQube version and rebuilt all my containers, I lost all my data.
How do I upgrade the sonarqube versions without loosing my data?