This image is base on latest Alpine Linux and the latest stable PostgreSQL release, without LLVM.
218
PostgreSQL is a powerful, open source object-relational database system with over 35 years of active development that has earned it a strong reputation for reliability, feature robustness, and performance.
This clion007/postgresql docker image is built from source on the latest Alpine Linux with a slim footprint. It ships a custom-compiled en+zh ICU bundle so Chinese text sorts and collates correctly without the full ICU data set, defaults to the Asia/Shanghai timezone, and automatically tracks the latest stable PostgreSQL release. The image publishes to Docker Hub (clion007/postgresql) and Alibaba Cloud (registry.cn-chengdu.aliyuncs.com/clion/postgresql).
This image is source-built on the latest Alpine and optimized for a minimal footprint. Compared to the official postgres:18-alpine:
| Item | This image | Official postgres:18-alpine |
|---|---|---|
| Image size (uncompressed) | ~80 MB | ~300 MB |
| JIT / LLVM | Not included | Included (speeds up complex queries at a large size cost) |
| ICU data | Custom-built en + zh | icu-data-full (all languages) |
| Procedural languages | No plperl / plpython / pltcl | Built, but their runtime libraries are not shipped either |
| Base image | clion007/alpine | alpine |
| Default timezone | Asia/Shanghai | UTC |
| Runtime user | PUID / PGID adjustable (default 70) | Fixed postgres (70) |
| Init logic | POSTGRES_* + initdb scripts + PUID / PGID / UMASK / TZ | POSTGRES_* + initdb scripts |
5432 by default.POSTGRES_USER, POSTGRES_PASSWORD and POSTGRES_DB variables.*.sh, *.sql, *.sql.gz, *.sql.xz or *.sql.zst scripts placed in /docker-entrypoint-initdb.d are executed once during initialization (in alphabetical order)./var/lib/postgresql/<PG_MAJOR>/docker inside the container, so mount the parent /var/lib/postgresql directory. A single mount point keeps the database upgradeable with pg_upgrade --link.You can deploy this container using either docker-compose (recommended) or the docker CLI.
services:
postgresql:
container_name: PostgreSQL
image: clion007/postgresql:latest
environment:
- POSTGRES_PASSWORD=changeme #required
- POSTGRES_USER=postgres
- POSTGRES_DB=postgres
- PUID=70
- PGID=70
- UMASK=022
- TZ=Asia/Shanghai
ports:
- 5432:5432
volumes:
- /etc/localtime:/etc/localtime:ro
- /path/to/postgresql/data:/var/lib/postgresql
restart: unless-stopped
docker run -d \
--name=PostgreSQL \
-e POSTGRES_PASSWORD=changeme `#required` \
-e POSTGRES_USER=postgres \
-e POSTGRES_DB=postgres \
-e PUID=70 \
-e PGID=70 \
-e UMASK=022 \
-e TZ=Asia/Shanghai \
-p 5432:5432 \
-v /path/to/postgresql/data:/var/lib/postgresql \
-v /etc/localtime:/etc/localtime:ro \
--restart unless-stopped \
clion007/postgresql:latest
Containers are configured using parameters passed at runtime. These parameters are separated by a colon and indicate <external>:<internal> respectively. For example, -p 5432:5432 would expose port 5432 from inside the container to be accessible from the host's IP on port 5432.
| Parameter | Function |
|---|---|
-p 5432:5432 | PostgreSQL TCP connection port |
| Parameter | Function |
|---|---|
-e POSTGRES_PASSWORD=changeme | Initial superuser password (required on first init) |
-e POSTGRES_USER=postgres | Initial superuser name (default: postgres) |
-e POSTGRES_DB=postgres | Initial database name (default: same as POSTGRES_USER) |
-e POSTGRES_INITDB_ARGS=... | Extra arguments passed to initdb |
-e POSTGRES_HOST_AUTH_METHOD=trust | Host auth method appended to pg_hba.conf (use trust only for testing, not recommended) |
-e PUID=70 | User ID for the postgres user (default: 70, Alpine standard) |
-e PGID=70 | Group ID for the postgres group (default: 70, Alpine standard) |
-e UMASK=022 | Control permission bits for newly created files (see Umask section) |
-e TZ=Asia/Shanghai | Specify timezone (default: Asia/Shanghai) |
| Parameter | Function |
|---|---|
-v /var/lib/postgresql | PostgreSQL data storage location. Mount the parent directory (not a subdirectory) to keep the database upgradeable |
Because this image automatically tracks the latest stable PostgreSQL release, upgrading the image may also bump the major version. Since PG 18, data is stored under /var/lib/postgresql/<major>/docker so that an existing single mount at /var/lib/postgresql stays on the same filesystem, which is required for pg_upgrade --link.
To upgrade the database across major versions:
pg_upgrade (or pg_upgrade --link) between the old and new data directories;Never start the new image on the old data directory layout without migrating, otherwise the container refuses to start and reports the detected old database locations.
This image provides the ability to override default permission settings using the optional -e UMASK=022 parameter. Remember that umask subtracts from permissions based on its value; it does not add permissions.
When using volumes, permission issues can arise between the host OS and the container. To avoid this, specify the user PUID and group PGID.
The postgres user/group defaults to 70 (the standard Alpine uid/gid). Ensure any volume directories on the host are owned by the same user you specify, and permission issues will be resolved automatically. For example, on Unraid set PUID/PGID to the owner of /mnt/user/appdata/postgresql.
5432 is correctly mapped and no other service occupies it;POSTGRES_PASSWORD was set on first initialization;docker logs PostgreSQL.POSTGRES_HOST_AUTH_METHOD=trust is used;Content type
Image
Digest
sha256:50976f45b…
Size
30.7 MB
Last updated
10 days ago
docker pull clion007/postgresql