Code Monkey home page Code Monkey logo

docker-postgresql's Introduction

docker-postgresql

Docker trusted build for PostgreSQL database

Version

PostgreSQL v9.3.3

Build from repository

$ git clone [email protected]:jllopis/docker-postgresql.git
$ cd docker-postgresql
$ docker build --rm -t my_user/postgresql:latest

Start

# 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

Ports

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.

PostgreSQL use

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;"

Examples

Create a user

psql -Upostgres --command "CREATE ROLE my_user WITH LOGIN ENCRYPTED PASSWORD 'very_secure_password';"

Create a database

psql -Upostgres --command "CREATE DATABASE testdb OWNER my_user ENCODING 'UTF-8';"

Drop a database

psql -Upostgres --command "DROP DATABASE testdb;"

How to restore data from a pg_dump backup

$ psql -Upostgres < path_to_dump_file.sql

docker-postgresql's People

Contributors

jllopis avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.