Supported tags and respective
For more information about this image and its history, please see the relevant manifest file (
library/postgres). This image is updated via pull requests to the
docker-library/official-images GitHub repo.
For detailed information about the virtual/transfer sizes and individual layers of each of the above supported tags, please see the
postgres/tag-details.md file in the
docker-library/docs GitHub repo.
What is PostgreSQL?
PostgreSQL, often simply "Postgres", is an object-relational database management system (ORDBMS) with an emphasis on extensibility and standards-compliance. As a database server, its primary function is to store data, securely and supporting best practices, and retrieve it later, as requested by other software applications, be it those on the same computer or those running on another computer across a network (including the Internet). It can handle workloads ranging from small single-machine applications to large Internet-facing applications with many concurrent users. Recent versions also provide replication of the database itself for security and scalability.
PostgreSQL implements the majority of the SQL:2011 standard, is ACID-compliant and transactional (including most DDL statements) avoiding locking issues using multiversion concurrency control (MVCC), provides immunity to dirty reads and full serializability; handles complex SQL queries using many indexing methods that are not available in other databases; has updateable views and materialized views, triggers, foreign keys; supports functions and stored procedures, and other expandability, and has a large number of extensions written by third parties. In addition to the possibility of working with the major proprietary and open source databases, PostgreSQL supports migration from them, by its extensive standard SQL support and available migration tools. And if proprietary extensions had been used, by its extensibility that can emulate many through some built-in and third-party open source compatibility extensions, such as for Oracle.
How to use this image
start a postgres instance
$ docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
This image includes
EXPOSE 5432 (the postgres port), so standard container linking will make it automatically available to the linked containers. The default
postgres user and database are created in the entrypoint with
The postgres database is a default database meant for use by users, utilities and third party applications.
connect to it from an application
$ docker run --name some-app --link some-postgres:postgres -d application-that-uses-postgres
... or via
$ docker run -it --link some-postgres:postgres --rm postgres sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres'
The PostgreSQL image uses several environment variables which are easy to miss. While none of the variables are required, they may significantly aid you in using the image.
This environment variable is recommended for you to use the PostgreSQL image. This environment variable sets the superuser password for PostgreSQL. The default superuser is defined by the
POSTGRES_USER environment variable. In the above example, it is being set to "mysecretpassword".
This optional environment variable is used in conjunction with
POSTGRES_PASSWORD to set a user and its password. This variable will create the specified user with superuser power and a database with the same name. If it is not specified, then the default user of
postgres will be used.
This optional environment variable can be used to define another location - like a subdirectory - for the database files. The default is
/var/lib/postgresql/data, but if the data volume you're using is a fs mountpoint (like with GCE persistent disks), Postgres
initdb recommends a subdirectory (for example
/var/lib/postgresql/data/pgdata ) be created to contain the data.
This optional environment variable can be used to define a different name for the default database that is created when the image is first started. If it is not specified, then the value of
POSTGRES_USER will be used.
How to extend this image
If you would like to do additional initialization in an image derived from this one, add one or more
*.sh scripts under
/docker-entrypoint-initdb.d (creating the directory if necessary). After the entrypoint calls
initdb to create the default
postgres user and database, it will run any
*.sql files and source any
*.sh scripts found in that directory to do further initialization before starting the service.
These initialization files will be executed in sorted name order as defined by the current locale, which defaults to
*.sql files will be executed by
POSTGRES_USER, which defaults to the
postgres superuser. It is recommended that any
psql commands that are run inside of a
*.sh script be executed as
POSTGRES_USER by using the
--username "$POSTGRES_USER" flag. This user will be able to connect without a password due to the presence of
trust authentication for Unix socket connections made inside the container.
You can also extend the image with a simple
Dockerfile to set a different locale. The following example will set the default locale to
FROM postgres:9.4 RUN localedef -i de_DE -c -f UTF-8 -A /usr/share/locale/locale.alias de_DE.UTF-8 ENV LANG de_DE.utf8
Since database initialization only happens on container startup, this allows us to set the language before it is created.
If there is no database when
postgres starts in a container, then
postgres will create the default database for you. While this is the expected behavior of
postgres, this means that it will not accept incoming connections during that time. This may cause issues when using automation tools, such as
fig, that start several containers simultaneously.
Supported Docker versions
This image is officially supported on Docker version 1.10.0.
Support for older versions (down to 1.6) is provided on a best-effort basis.
Please see the Docker installation documentation for details on how to upgrade your Docker daemon.
Documentation for this image is stored in the
postgres/ directory of the
docker-library/docs GitHub repo. Be sure to familiarize yourself with the repository's
README.md file before attempting a pull request.
You can also reach many of the official image maintainers via the
#docker-library IRC channel on Freenode.
You are invited to contribute new features, fixes, or updates, large or small; we are always thrilled to receive pull requests, and do our best to process them as fast as we can.
Before you start to code, we recommend discussing your plans on the mailing list or through a GitHub issue, especially for more ambitious contributions. This gives other contributors a chance to point you in the right direction, give you feedback on your design, and help you find out if someone else is working on the same thing.
@itamarost get rid of one s in the word postgress:
docker pull postgres:9.4.5 works.
what happened to the 9.4.5 images?
$ docker pull postgress:9.4.5
Pulling repository docker.io/library/postgress
Error: image library/postgress:9.4.5 not found
@yatskovsky - that is a common error on Kitematic if you've changed networks since starting your Docker Machine VM - ensure that the VM is destroyed when shutting down Kitematic (see settings), then when you see that, shut down Kitematic, and restart, and it should resolve.
Hi, does anybody know how to pull this on a Windows Server 2016 with Components?
'docker pull postgres' says
Pulling repository docker.io/library/postgres
Error: image library/postgres:latest not found
I need to specify the docker's ip address and use the variable PGDATA but I couldn't do it. Could anyone help me?
Is it possible to have two databases with two different users/roles inside this container?
Is there an easy way to import db data on a build time (not as a part of 'run' startup)?
Hey, I created a postgres container and a tomcat container and linked them. My app accesses the db fine, creates tables ect ect but the roles are not created. Any one faced the same issue? any help would be appreciated.
Does anybody have an example of how to extend the image to include an already populated database? The database that I want to import takes about 15 minutes to import, thus have it create it during the startup would take too long. Also, how could I possibly persist this inbetween startups and stops?
Why does the following NOT work: I mount /var/lib/postgresql from GCE and leave PGDATA on its default value /var/lib/postgresql/data? If I try this, the database is re-created every time thid container starts. Moving both paths one level deeper, i.e. mounting /var/lib/postgresql/data and setting PGDATA to /var/lib/postgresql/data/pgdata works. Why?