PostgreSQL Docker image
How to use this image
start a postgres instance
docker run -d --name postgres -v /host/data:/var/lib/postgresql/data -e POSTGRES_ROOT_PASSWORD=mysecretpassword -e POSTGRES_USER=user -e POSTGRES_PASSWORD=secret -e POSTGRES_DB=app healthcareblocks/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.
- POSTGRES_ROOT_PASSWORD - password for superuser (postgres)
- POSTGRES_USER - name of standard user
- POSTGRES_PASSWORD - password for standard user
- POSTGRES_DB - initial database to create
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.
Overriding the Configuration File
This image uses internal Postgres defaults when starting up. Inside the image a sample configuration file can be found at /usr/share/postgresql/postgresql.conf.sample.
To use your own config file, create a volume mount for a file stored in the host machine mapped to /etc/postgresql/postgresql.conf.override inside the container.
docker run -d --name postgres \ -v /host/postgresql.conf:/etc/postgresql/postgresql.conf \ -v /host/data:/var/lib/postgresql/data \ -e POSTGRES_PASSWORD=mysecretpassword healthcareblocks/postgres
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.
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
docker-compose, that start several containers simultaneously.
i am thinking we would want to enable ssl support on this image so that we can test realistically what is going on with secure connection