https://github.com/hopsoft/docker-postgres
Trusted Docker Image for PostgreSQL
https://github.com/hopsoft/docker-postgres
Last synced: 2 months ago
JSON representation
Trusted Docker Image for PostgreSQL
- Host: GitHub
- URL: https://github.com/hopsoft/docker-postgres
- Owner: hopsoft
- License: mit
- Created: 2014-07-08T22:37:08.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-11-07T23:20:59.000Z (almost 11 years ago)
- Last Synced: 2025-04-04T03:43:46.468Z (6 months ago)
- Language: Shell
- Size: 309 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Trusted Docker Image for PostgreSQL
This image contains a basic install of [PostgreSQL](http://www.postgresql.org/)
with [contrib](http://www.postgresql.org/docs/9.3/static/contrib.html),
[PostGIS](http://postgis.net/), & [pgRouting](http://pgrouting.org/)._No roles/users or databases have been created._
## Setup
1. Create a directory on the __host__ to hold the `pgdata` files
```sh
mkdir /path/to/pgdata
```1. Start & stop the container to initialize the database
```sh
docker run --name pg --restart=always -d -p 5432:5432 -v /path/to/pgdata:/pgdata hopsoft/postgres
docker stop pg
```1. Update the config files
_This config setup is insecure & temporary. We only use it to create a superuser._
```sh
vim /path/to/pgdata/postgresql.conf# set the following
# listen_addresses = '*'
``````sh
vim /path/to/pgdata/pg_hba.conf# add the following line
# TYPE DATABASE USER ADDRESS METHOD
# host all postgres 0.0.0.0/0 trust
```1. Start the container & create a superuser
```sh
docker start pg
psql -h "$(docker inspect pg | grep IPAddress | cut -d '"' -f 4)" -U postgres
``````sql
CREATE ROLE root SUPERUSER LOGIN PASSWORD 'secret';
CREATE DATABASE root OWNER root;
```_Be sure to change the username/password to something more secure._
1. Stop the container
```sh
docker stop pg
```## Production Use
1. Modify the configuration files for production use
```sh
vim /path/to/pgdata/pg_hba.conf# delete this line
# TYPE DATABASE USER ADDRESS METHOD
# host all postgres 0.0.0.0/0 trust
#
# add one of the following line(s)... the second is more secure
# TYPE DATABASE USER ADDRESS METHOD
# host all root 0.0.0.0/0 md5
# host all root HOST_IP_ADDRESS/32 md5
```#### Optional
```sh
vim /path/to/pgdata/postgresql.conf# optionally set the following
# it will tighten security by only allowing the host to connect
# listen_addresses = 'CONTAINER_IP_ADDRESS'
```1. Start the container for production use
```sh
docker start pg
```1. Connect to postgres
```sh
psql -h "$(docker inspect pg | grep IPAddress | cut -d '"' -f 4)" -U root
```## Configuration Changes
1. Modify the configuration files
```sh
vim /path/to/pgdata/postgresql.conf
vim /path/to/pgdata/pg_hba.conf
```1. Restart the container
```sh
docker restart pg
```## Building the Image
For those who want to build the image manually.
## Linux
```sh
git clone https://github.com/hopsoft/docker-postgres.git
cd docker-postgres
docker build -t hopsoft/postgres /vagrant
```### OSX
```sh
git clone https://github.com/hopsoft/docker-postgres.git
cd docker-postgres
vagrant up
vagrant ssh
sudo docker build -t hopsoft/postgres /vagrant
```