Docker trusted build for PostgreSQL database
PostgreSQL v9.3.3
$ git clone [email protected]:jllopis/docker-postgresql.git
$ cd docker-postgresql
$ docker build --rm -t my_user/postgresql:latest
# docker run -d -p 5432:5432 \
-v {local_etc_fs}:/etc/postgresql \
-v {local_log_fs}:/var/log/postgresql \
-v {local_lib_fs}:/var/lib/postgresql \
-t -h {node_host_name} -name {image_name} my_user/postgresql:latest
where:
- local_XXX_fs is the local storage to keep data safe. If not specified it will use the container so the data will be lost upon restart.
- node_hostname is the name that will hold the HOSTNAME variable inside the container. This is accessible to CMD so etcd will use it as their node name. If not specified a default name wil be used.
- image_name is the name given to the image so you don't have to play with ids
You can also start postgresql image with command line options:
# docker run -d -p 7777:7777 \
-v {local_etc_fs}:/etc/postgresql \
-v {local_log_fs}:/var/log/postgresql \
-v {local_lib_fs}:/var/lib/postgresql \
-t -h {node_host_name} -name {image_name} \
my_user/postgresql:latest -c config_file=/etc/postgresql/other_postgresql.conf
The ports used are:
- 5432
Remember that if you want access from outside the container you must explicitly tell docker to do so by setting -p at image launch.
By default, a postgres user is created and given a password (default password: secret). It is highly encouraged that you change this password for your own.
To change the password issue:
psql --command "ALTER USER postgres ENCRYPTED PASSWORD 'secret';"
Change 'secret' for your highly secure password.
Usually you can modify the database (manage users, databases, etc) by executing psql commands from your host by way of the postgres user:
psql -Upostgres --command "SQL COMMAND;"
psql -Upostgres --command "CREATE ROLE my_user WITH LOGIN ENCRYPTED PASSWORD 'very_secure_password';"
psql -Upostgres --command "CREATE DATABASE testdb OWNER my_user ENCODING 'UTF-8';"
psql -Upostgres --command "DROP DATABASE testdb;"
$ psql -Upostgres < path_to_dump_file.sql