Public Repository

Last pushed: 2 years ago
Short Description
Postgresql in Docker containers on ARM devices
Full Description


Postgresql in Docker containers on ARM devices


You have a Docker network named 'postgres' (docker network create postgres)

New container

export DOCKER_DATA=/docker/data && \
export PSQL_VERSION=9.4 && \
docker run -it --rm \
    --name postgres -p 5432:5432 \
    --net=postgres \
    -v $DOCKER_DATA/postgres/data:/var/lib/postgresql/$PSQL_VERSION/main \
    -v $DOCKER_DATA/postgres/conf:/etc/postgresql/$PSQL_VERSION/main \
    -v $DOCKER_DATA/postgres/log:/var/log/postgresql/ \

Now modify /etc/postgresql/$PSQL_VERSION/main/pg_hba.conf with

#host all postgres trust #only if your apps need to?
host all all md5

and postgresql.conf with
listen_addresses = '*'
(or choose safer controls if your device is externally accessible - I'm using LAN)

Quit the container and rerun the same command.


You have a container with PostgreSQL accessible (to other containers on the same network, --net=postgres) by hostname 'postgres' and port 5432. It is also accessible outside the docker network by the host's hostname and port 5432. Data is persisted to $DOCKER_DATA. If you remove the postgres container and start a new container while $DOCKER_DATA already has data, the new container will use the old database.


Docker has known problems with file permissions in mounted volumes. Normally the postgresql service won't start unless the config and data owner are the same as the configured cluster owner (not the case when mounting volumes). I got around that by creating the cluster with the host's root user -u 0 (which differs from the container's root user).

Docker Pull Command