robertbruno/postgres-docker-image

By robertbruno

Updated over 2 years ago

postgres-docker-image

Image
0

187

robertbruno/postgres-docker-image repository overview

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.

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 >

For more information visit:

Tag summary

Content type

Image

Digest

sha256:9c3816c71

Size

566.9 MB

Last updated

over 2 years ago

docker pull robertbruno/postgres-docker-image