Another PostgreSQL Docker image running on Alpine Linux
895
Docker has an official image maintained by the PostgreSQL Docker Community. This variation is inspired by onjin. Original of this document is here.
Brief description:
postgres is used to run the service. The user's UID/GID is adjustable. Default is 70. As compiled: uid=1002, gid=1002POSTGRES_USER - This optional variable will create the specified user with superuser power.POSTGRES_PASSWORD - manadatory password for POSTGRES_USERPOSTGRES_DB - This variable will create the specified database and grant access to this database to POSTGRES_USER/var/lib/postgresql - directory for configuration files and databasesIt will create a new DB in the specified volume:
docker run -d \
--name pgsql \
-e VERBOSE=1 \
-e POSTGRES_USER=eugene \
-e POSTGRES_PASSWORD="Hard2Gue$$Password" \
-e POSTGRES_DB=syslog \
-p 5432:5432 \
-v /data/postgresql:/var/lib/postgresql \
etaylashev/postgresql
The entrypoint.sh script creates the following pg_hba.conf file:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all postgres trust
local all all md5
# IPv4 connections:
host all all 0.0.0.0/0 md5
To logon as the default superuser postgres to the running container without a password:
docker exec -it <container_name> /usr/bin/psql -U postgres postgres
To logon as the created user to the specified DB with password:
docker exec -it <container_name> /usr/bin/psql -W -U <user_name> <created_db>
To run the exitsting DB:
docker run -d \
--name pgsql \
-e VERBOSE=1 \
-p 5432:5432 \
-v /data/postgresql:/var/lib/postgresql \
etaylashev/postgresql
To run it like a pod:
apiVersion: v1
kind: Pod
metadata:
name: pgsql
namespace: default
labels:
app: postgresql
purpose: database
spec:
volumes:
- name: "pgsql-data"
hostPath:
path: "/data/postgresql/"
containers:
- name: pgsql
image: etaylashev/postgresql
env:
- name: VERBOSE
value: "1"
volumeMounts:
- name: "pgsql-data"
mountPath: "/var/lib/postgresql"
ports:
- containerPort: 5432
protocol: TCP
See documentation. There are at least two options to backup:
tar czf my_pgsql-$(date "+%Y%m%d").tgz /data/postgresql/
pg_dump for a database or pg_dumpall for all:docker exec <container_name> /bin/sh -c "/sbin/su-exec postgres /usr/bin/pg_dumpall -w " >/backup/my_dbs.sql
See documentation
docker exec <container_name> /bin/sh -c "/sbin/su-exec postgres /usr/bin/psql --set ON_ERROR_STOP=on -w " </backup/my_dbs.sql
Content type
Image
Digest
Size
69.2 MB
Last updated
almost 5 years ago
docker pull etaylashev/postgresql