### Start a PostgreSQL container with docker run Source: https://hub.docker.com/_/postgres Starts a PostgreSQL container named some-postgres with the superuser password set via POSTGRES_PASSWORD. The default postgres user and database are created by the entrypoint using initdb. ```bash $ docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres ``` -------------------------------- ### Run PostgreSQL with docker compose Source: https://hub.docker.com/_/postgres Example compose.yaml for running PostgreSQL with Adminer. Run docker compose up, wait for initialization, then visit http://localhost:8080 or http://host-ip:8080. ```yaml # Use postgres/example user/password credentials services: db: image: postgres restart: always # set shared memory limit when using docker compose shm_size: 128mb # or set shared memory limit when deploy via swarm stack #volumes: # - type: tmpfs # target: /dev/shm # tmpfs: # size: 134217728 # 128*2^20 bytes = 128Mb environment: POSTGRES_PASSWORD: example adminer: image: adminer restart: always ports: - 8080:8080 ``` -------------------------------- ### Set locale in Alpine-based image with POSTGRES_INITDB_ARGS Source: https://hub.docker.com/_/postgres Set the default locale for a newly initialized database in Alpine-based images using POSTGRES_INITDB_ARGS. Alpine variants starting with Postgres 15 support ICU locales; earlier Alpine versions do not support locales. ```bash $ docker run -d -e LANG=de_DE.utf8 -e POSTGRES_INITDB_ARGS="--locale-provider=icu --icu-locale=de-DE" -e POSTGRES_PASSWORD=mysecretpassword postgres:15-alpine ``` -------------------------------- ### Run PostgreSQL with a custom config file Source: https://hub.docker.com/_/postgres Use a custom PostgreSQL config file by copying the sample from the container, customizing it, and mounting it with -v. Set listen_addresses = '*' in the config so other containers can access PostgreSQL. The -c 'config_file=...' option points the server to the mounted config. ```bash $ # get the default config $ docker run -i --rm postgres cat /usr/share/postgresql/postgresql.conf.sample > my-postgres.conf $ # customize the config $ # run postgres with custom config $ docker run -d --name some-postgres -v "$PWD/my-postgres.conf":/etc/postgresql/postgresql.conf -e POSTGRES_PASSWORD=mysecretpassword postgres -c 'config_file=/etc/postgresql/postgresql.conf' ``` -------------------------------- ### Initialize additional user and database with init-user-db.sh Source: https://hub.docker.com/_/postgres Place this script in /docker-entrypoint-initdb.d to create an additional user and database during initialization. Scripts run only when the data directory is empty; a failure causes the entrypoint to exit and scripts won't rerun on restart. Use --username "$POSTGRES_USER" to connect without a password via the Unix socket. ```bash #!/usr/bin/env bash set -e psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL CREATE USER docker; CREATE DATABASE docker; GRANT ALL PRIVILEGES ON DATABASE docker TO docker; EOSQL ``` -------------------------------- ### Connect to PostgreSQL via psql Source: https://hub.docker.com/_/postgres Connects to a running PostgreSQL container via the psql client. The output shows the psql version and the result of a simple SELECT query. ```bash $ docker run -it --rm --network some-network postgres psql -h some-postgres -U postgres psql (14.3) Type "help" for help. postgres=# SELECT 1; ?column? ---------- 1 (1 row) ``` -------------------------------- ### Set PostgreSQL options with -c on docker run Source: https://hub.docker.com/_/postgres Set PostgreSQL server options directly on the docker run line using -c. Any option available in a .conf file can be set this way; the entrypoint passes options to the postgres daemon. ```bash $ docker run -d --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword postgres -c shared_buffers=256MB -c max_connections=200 ``` -------------------------------- ### Run postgres image with arbitrary --user Source: https://hub.docker.com/_/postgres Shows two docker run invocations with different --user values and their outputs. The first runs as user www-data and succeeds; the second uses numeric UID 1000:1000 and fails because initdb cannot look up the effective user ID. ```bash $ docker run -it --rm --user www-data -e POSTGRES_PASSWORD=mysecretpassword postgres The files belonging to this database system will be owned by user "www-data". ... $ docker run -it --rm --user 1000:1000 -e POSTGRES_PASSWORD=mysecretpassword postgres initdb: could not look up effective user ID 1000: user does not exist ``` -------------------------------- ### Set default locale with Dockerfile for Debian-based images Source: https://hub.docker.com/_/postgres Extend the Debian-based image with a Dockerfile to set a different locale, here de_DE.utf8. Since database initialization only happens on container startup, this sets the language before the database is created. ```dockerfile FROM postgres:14.3 RUN localedef -i de_DE -c -f UTF-8 -A /usr/share/locale/locale.alias de_DE.UTF-8 ENV LANG de_DE.utf8 ``` -------------------------------- ### Pull postgres:17.11-trixie Source: https://hub.docker.com/_/postgres/tags Pulls the PostgreSQL 17.11-trixie image from Docker Hub. ```bash docker pull postgres:17.11-trixie ``` -------------------------------- ### docker pull postgres:19beta4-alpine3.23 Source: https://hub.docker.com/_/postgres/tags Pull the Postgres 19 beta 4 image based on Alpine 3.23. This tag was last pushed 6 days ago and supports multiple architectures. ```bash docker pull postgres:19beta4-alpine3.23 ``` -------------------------------- ### Pull postgres:15.19-trixie Source: https://hub.docker.com/_/postgres/tags Pulls the PostgreSQL 15.19-trixie image from Docker Hub. ```bash docker pull postgres:15.19-trixie ``` -------------------------------- ### docker pull postgres:19beta4-alpine3.24 Source: https://hub.docker.com/_/postgres/tags Pull the Postgres 19 beta 4 image based on Alpine 3.24. This tag was last pushed 6 days ago and supports multiple architectures. ```bash docker pull postgres:19beta4-alpine3.24 ``` -------------------------------- ### Pull postgres:18.6-trixie Source: https://hub.docker.com/_/postgres/tags Pulls the PostgreSQL 18.6-trixie image from Docker Hub. ```bash docker pull postgres:18.6-trixie ``` -------------------------------- ### Pull postgres:latest Source: https://hub.docker.com/_/postgres/tags Pulls the PostgreSQL latest image from Docker Hub. ```bash docker pull postgres:latest ``` -------------------------------- ### Pull postgres:15-trixie Source: https://hub.docker.com/_/postgres/tags Pulls the PostgreSQL 15-trixie image from Docker Hub. ```bash docker pull postgres:15-trixie ``` -------------------------------- ### Pull postgres:17-trixie Source: https://hub.docker.com/_/postgres/tags Pulls the PostgreSQL 17-trixie image from Docker Hub. ```bash docker pull postgres:17-trixie ``` -------------------------------- ### docker pull postgres:19beta4-bookworm Source: https://hub.docker.com/_/postgres/tags Pull the Postgres 19 beta 4 image based on Debian bookworm. This tag was last pushed 10 days ago and supports multiple architectures. ```bash docker pull postgres:19beta4-bookworm ``` -------------------------------- ### docker pull postgres:19beta4-trixie Source: https://hub.docker.com/_/postgres/tags Pull the Postgres 19 beta 4 image based on Debian trixie. This tag was last pushed 6 days ago and supports multiple architectures. ```bash docker pull postgres:19beta4-trixie ``` -------------------------------- ### Pull postgres:17.11 Source: https://hub.docker.com/_/postgres/tags Pulls the PostgreSQL 17.11 image from Docker Hub. ```bash docker pull postgres:17.11 ``` -------------------------------- ### Pull postgres:trixie Source: https://hub.docker.com/_/postgres/tags Pulls the PostgreSQL trixie image from Docker Hub. ```bash docker pull postgres:trixie ``` -------------------------------- ### Pull postgres:15 Source: https://hub.docker.com/_/postgres/tags Pulls the PostgreSQL 15 image from Docker Hub. ```bash docker pull postgres:15 ``` -------------------------------- ### docker pull postgres:19beta4 Source: https://hub.docker.com/_/postgres/tags Pull the Postgres 19 beta 4 image with the default variant. This tag was last pushed 6 days ago and supports multiple architectures. ```bash docker pull postgres:19beta4 ``` -------------------------------- ### Pull postgres:17 Source: https://hub.docker.com/_/postgres/tags Pulls the PostgreSQL 17 image from Docker Hub. ```bash docker pull postgres:17 ``` -------------------------------- ### Pull postgres:15.19 Source: https://hub.docker.com/_/postgres/tags Pulls the PostgreSQL 15.19 image from Docker Hub. ```bash docker pull postgres:15.19 ``` -------------------------------- ### Set POSTGRES_HOST_AUTH_METHOD in pg_hba.conf Source: https://hub.docker.com/_/postgres Approximate line used to populate pg_hba.conf when POSTGRES_HOST_AUTH_METHOD is set on an uninitialized database. The default authentication method is scram-sha-256 in PostgreSQL 14+ (md5 in older releases). Avoid using trust because it allows passwordless connections. ```bash echo "host all all all $POSTGRES_HOST_AUTH_METHOD" >> pg_hba.conf ``` -------------------------------- ### docker pull postgres:16.15-trixie Source: https://hub.docker.com/_/postgres/tags Pull the Postgres 16.15 image based on Debian trixie. This tag was last pushed 10 days ago and supports multiple architectures. ```bash docker pull postgres:16.15-trixie ``` -------------------------------- ### docker pull postgres:14.24-trixie Source: https://hub.docker.com/_/postgres/tags Pull the Postgres 14.24 image based on Debian trixie. This tag was last pushed 10 days ago and supports multiple architectures. ```bash docker pull postgres:14.24-trixie ``` -------------------------------- ### docker pull postgres:16.15 Source: https://hub.docker.com/_/postgres/tags Pull the Postgres 16.15 image with the default variant. This tag was last pushed 10 days ago and supports multiple architectures. ```bash docker pull postgres:16.15 ``` -------------------------------- ### docker pull postgres:19beta4-alpine Source: https://hub.docker.com/_/postgres/tags Pull the Postgres 19 beta 4 image using the default Alpine variant. This tag was last pushed 6 days ago and supports multiple architectures. ```bash docker pull postgres:19beta4-alpine ``` -------------------------------- ### Use Docker secret for POSTGRES_PASSWORD Source: https://hub.docker.com/_/postgres Runs a PostgreSQL container using a Docker secret file for the password. The _FILE suffix is supported for POSTGRES_INITDB_ARGS, POSTGRES_PASSWORD, POSTGRES_USER, and POSTGRES_DB. ```bash $ docker run --name some-postgres -e POSTGRES_PASSWORD_FILE=/run/secrets/postgres-passwd -d postgres ``` -------------------------------- ### Pull postgres image Source: https://hub.docker.com/_/postgres Pulls the postgres Docker image from Docker Hub. ```bash docker pull postgres ``` -------------------------------- ### docker pull postgres:14.24 Source: https://hub.docker.com/_/postgres/tags Pull the Postgres 14.24 image with the default variant. This tag was last pushed 10 days ago and supports multiple architectures. ```bash docker pull postgres:14.24 ``` -------------------------------- ### docker pull postgres:16-trixie Source: https://hub.docker.com/_/postgres/tags Pull the latest Postgres 16 image based on Debian trixie. This tag was last pushed 10 days ago and supports multiple architectures. ```bash docker pull postgres:16-trixie ``` -------------------------------- ### docker pull postgres:16 Source: https://hub.docker.com/_/postgres/tags Pull the latest Postgres 16 image with the default variant. This tag was last pushed 10 days ago and supports multiple architectures. ```bash docker pull postgres:16 ``` -------------------------------- ### docker pull postgres:14-trixie Source: https://hub.docker.com/_/postgres/tags Pull the latest Postgres 14 image based on Debian trixie. This tag was last pushed 10 days ago and supports multiple architectures. ```bash docker pull postgres:14-trixie ``` -------------------------------- ### docker pull postgres:14 Source: https://hub.docker.com/_/postgres/tags Pull the latest Postgres 14 image with the default variant. This tag was last pushed 10 days ago and supports multiple architectures. ```bash docker pull postgres:14 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.