Giter Club home page Giter Club logo

postgres-docker-image's Introduction

postgres-docker-image

General purpose postgresql docker image with some preloaded extensions.

It is based on the official postgres image so the same characteristics apply.

The main features of this image are:

  • postgis extends the capabilities of the PostgreSQL relational database by adding support for storing, indexing, and querying geospatial data.

  • plperl PL/Perl is a loadable procedural language that enables you to write PostgreSQL functions and procedures in the Perl programming language.The following modules libwww-perl and API::Google come pre-installed.

  • plpython3u The PL/Python procedural language allows PostgreSQL functions and procedures to be written in the Python language.

Security Considerations: PL/Python is considered an untrusted language in PostgreSQL because Python code executed through it can access the host machine's file system. There is no built-in mechanism to restrict this access, so caution should be used when using PL/Python functions.

  • pg-safeupdate is a simple PostgreSQL extension that generates an error if UPDATE and DELETE are executed without specifying conditions (WHERE). This extension was initially designed to protect data from accidentally deleting data that PostgREST can write to.

Make this mandatory for all databases and connections by adding the following to postgresql.conf:

shared_preload_libraries=safeupdate

Once loaded this extension can be administratively disabled by setting

SET safeupdate.enabled=0;
  • wait-for-it.sh is a pure bash script that will wait on the availability of a host and TCP port

Build

This section indicates the steps to build the postgres image based on Dockerfile, where postgresql-docker-image is the name of the image to be generated and latest is the tag. The necessary requirements to build the image are:

  • docker

For the latest version use the default dockerfile.

# clone local repo
git clone https://github.com/robertbruno/postgres-docker-image

# We enter the root of the project.
cd postgres-docker-image

# we execute the image build
docker build -t postgres-docker-image -f Dockerfile .

Use

You can use the images already published:

mkdir -p ~/docker/volume/postgres && \
    docker run --name db -p 5432:5432 \
    -v ~/docker/volume/postgres:/var/lib/postgresql/data \
    robertbruno/postgres-docker-image:latest

It is important that you define a volume for the server data otherwise you will lose the changes when the container execution ends.

You can indicate different connection information

mkdir -p ~/docker/volume/postgres && \
    docker run --name db -p 5432:5432 \
    -v ~/docker/volume/postgres:/var/lib/postgresql/data \
    -e POSTGRES_USER=my_user \
    -e POSTGRES_DB=my_database \
    -e POSTGRES_PASSWORD=my_password \
    robertbruno/postgres-docker-image:latest

Backup

You will need to run the following command and replace the necessary values:

 docker exec -t < container id > \
 pg_dump  --port 5432   --username my_user_name \
 --no-password --format plain --encoding UTF8 \
  dbname  >  backup_postgresql_`date +%d-%m-%Y"_"%H_%M_%S`.sql

Restore

Having a backup in sql format, you can run it in your container by running the following command and replacing the necessary values:

cat ~/restore.sql  | docker exec -i < container id > psql > -U < user > -d < database >

PaFor more information visit:

postgres-docker-image's People

Contributors

robertbruno 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.