Sentry update from 10.0.0 (Postgres11) to actual release

Hello. We have On-Premise Sentry v10.0.0 that we want to update to the latest version. However, we have a problem, this installation of Sentry v10.0.0 is used with Postgres 11.1 Docker image. In source files, docker-compose Sentry must use Postgres 9.6.

We cannot update Sentry because the update process is crashing.

If use the original docker-compose file on update to Sentry 21.6.0 (Postgres 9.6 Docker image):

**Trace ./install.sh:**
  File "/usr/local/lib/python3.6/site-packages/psycopg2/__init__.py", line 130, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not translate host name "postgres" to address: Temporary failure in name resolution

1
An error occurred, caught SIGERR on line 12
Cleaning up...
**Logs from Postgres (docker logs postgres9.6 docker image):**
Setting up Change Data Capture
Replication config already present in pg_hba. Not changing anything.

PostgreSQL Database directory appears to contain a database; Skipping initialization

FATAL:  "/var/lib/postgresql/data" is not a valid data directory
DETAIL:  File "/var/lib/postgresql/data/PG_VERSION" does not contain valid data.
HINT:  You might need to initdb.

If use the original docker-compose file on update to Sentry 21.6.0 (with Postgres 11.1 Docker image):

**Trace ./install.sh:**
10:57:44 [WARNING] sentry.utils.geo: Error opening GeoIP database: /geoip/GeoLite2-City.mmdb
10:57:44 [WARNING] sentry.utils.geo: Error opening GeoIP database in Rust: /geoip/GeoLite2-City.mmdb
10:57:48 [INFO] sentry.plugins.github: apps-not-configured
Error: It looks like you've skipped a hard stop in our upgrade process. Please follow the upgrade process here: https://develop.sentry.dev/self-hosted/#hard-stops
1
An error occurred, caught SIGERR on line 12
Cleaning up...
**Logs from Postgres (docker logs postgres11.1 docker image):**
Setting up Change Data Capture
Replication config already present in pg_hba. Not changing anything.
You need to install postgresql-server-dev-NN for building a server-side extension or libpq-dev for building a client-side application.
2021-07-21 11:46:11.631 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2021-07-21 11:46:11.631 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2021-07-21 11:46:11.764 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-07-21 11:46:12.114 UTC [32] LOG:  database system was shut down at 2021-07-21 10:57:50 UTC
2021-07-21 11:46:12.538 UTC [1] LOG:  database system is ready to accept connections
2021-07-21 11:46:23.800 UTC [1] LOG:  received smart shutdown request
2021-07-21 11:46:24.077 UTC [1] LOG:  background worker "logical replication launcher" (PID 38) exited with exit code 1
2021-07-21 11:46:24.077 UTC [33] LOG:  shutting down
2021-07-21 11:46:25.160 UTC [1] LOG:  database system is shut down

How can I update Sentry without losing my database? How can the situation be rectified so that this does not happen again in the future?
Thanks.