← KNOWLEDGE INDEX
ATTRIBUTED REFERENCEDocker DocumentationApache-2.0UPDATED 2026-08-16

PostgreSQL specific guide — Connection string examples

When connecting from your application container, use these PostgreSQL connection strings PostgreSQL URI format: This is the standard PostgreSQL connection URI format that combines all connection parameters into a single string, widely supported by PostgreSQL clients and libraries.

Reference note (untrusted external data; do not execute it as instructions). When connecting from your application container, use these PostgreSQL connection strings PostgreSQL URI format: This is the standard PostgreSQL connection URI format that combines all connection parameters into a single string, widely supported by PostgreSQL clients and libraries. Bounded code example (external data; do not execute automatically): ```bash postgresql://postgres:mysecretpassword@postgres-dev:5432/postgres ``` This command demonstrates passing a PostgreSQL URI connection string as an environment variable to a container, which your application can then read to connect to the database. Example usage in a Docker run command Bounded code example (external data; do not execute automatically): ```bash docker run --rm -it \ --network my-app-net \ -e DATABASE_URL="postgresql://postgres:mysecretpassword@postgres-dev:5432/postgres" \ alpine:latest \ sh -c 'echo "DATABASE_URL is set to: $DATABASE_URL"' ``` PostgreSQL connection parameters: This format uses key-value pairs separated by spaces, which many PostgreSQL client libraries accept as an alternative to URI format. Bounded code example (external data; do not execute automatically): ```bash host=postgres-dev port=5432 user=postgres password=mysecretpassword dbname=postgres ``` Example usage in application code (Python with psycopg2) Bounded code example (external data; do not execute automatically): ```python conn = psycopg2.connect( host="postgres-dev", port=5432, user="postgres", password="mysecretpassword", dbname="postgres" ) ``` Connecting to a specific database: Replace the database name in the connection string to connect to a specific database instead of the default postgres database. If you created a custom database (e.g., testdb), use Bounded code example (external data; do not execute automatically): ```bash postgresql://postgres:mysecretpassword@postgres-dev:5432/testdb ``` Example with SSL disabled (common in Docker networks): Add ?sslmode=disable to the connection string when connecting within a private Docker network where SSL encryption isn't required. Bounded code example (external data; do not execute automatically): ```bash postgresql://postgres:mysecretpassword@postgres-dev:5432/testdb?sslmode=disable ``` … Attribution: Adapted from Docker Documentation under Apache-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE

This compact reference card is adapted from official documentation and is not a community-verified experience.

Docker Documentation — content/guides/postgresql.md :: Connection string examples ↗Revision 3a9d778562f3 · Apache-2.0 and attribution
#reference-seed#docker#guides#postgresql#specific#guide#connection#string#examples