-v /datadocker/postgres/data:/var/lib/postgresql/data \ postgres:18.6Error: in 18+, these Docker images are configured to store database data in a format which is compatible with "pg_ctlcluster" (specifically, using major-version-specific directory names). This better reflects how PostgreSQL itself works, and how upgrades are to be performed. See also https://github.com/docker-library/postgres/pull/1259 Counter to that, there appears to be PostgreSQL data in: /var/lib/postgresql/data (unused mount/volume) This is usually the result of upgrading the Docker image without upgrading the underlying database using "pg_upgrade" (which requires both versions). The suggested container configuration for 18+ is to place a single mount at /var/lib/postgresql which will then place PostgreSQL data in a subdirectory, allowing usage of "pg_upgrade --link" without mount point boundary issues. See https://github.com/docker-library/postgres/issues/37 for a (long) discussion around this process, and suggestions for how to do so.
reason
1.if /datadocker/postgres/data contains files from an older version (like Postgres 15, 16, or 17).
2.if /datadocker/postgres contains files from an older version (like Postgres 18, or 19).
The error occurs because starting with PostgreSQL 18, the official Docker image has changed its default data directory layout
. It no longer stores database files directly inside /var/lib/postgresql/data. Instead, it uses major-version-specific directories (e.g., /var/lib/postgresql/18/docker) to make future upgrades much easier.
When you try to map your host folder directly to /var/lib/postgresql/data, the container detects your existing, older database files in an unassigned mount point and intentionally errors out to prevent data corruption.
Mount your volume directly to /var/lib/postgresql. The image will automatically create a new version-specific subdirectory (/var/lib/postgresql/18/docker) inside it.
docker run -d \
--name my-postgres \
-v /datadocker/postgres:/var/lib/postgresql \
-e POSTGRES_PASSWORD=your_password \
postgres:18.6When PostgreSQL 19 or 20 comes out in the future, you will be able to upgrade your database seamlessly using fast hardlinks (pg_upgrade --link) without hitting any mount boundary errors.
