A Docker container for PostgreSQL 9.3 with special features. Available for pulling from Docker Hub Registry.
Features:
- Based on Ubuntu 14.04 and phusion/baseimage-docker
- PostgreSQL 9.3
- Automatically create your PostgreSQL superuser with the given password
- Integrated SSH server
- Add your public key to the container's SSH server for an easy access
- Expose to the host the ports 22 (SSH) and 5432 (PostgreSQL)
- Share PostgreSQL data directory and log files with the host and other Docker containers
Links:
- Docker Hub Registry
- Project page in my website
$ docker build -t nimiq/postgresql .
-p 2223:22
Port 22 (SSH) in the container will be exposed to port 2223 in the host. You can use the host port 2223 or any other port, but you must use the container port 22.-p 5432:5432
Port 5432 (PostgreSQL) in the container will be exposed to port 5432 in the host. You can use the host port 5432 or any other port, but you must use the container port 5432.--volume=/mylocaldir:/srv/pgdata
The dir /mylocaldir in the host will be mounted to /srv/pgdata in the container. This dir must be emtpy. You can use the local dir /mylocaldir or any other dir, but you must use the container dir /srv/pgdata.-e "PG_USERNAME=myuser"
The username to be used when creating a new ROLE in PostgreSQL.-e "PG_PASSWORD=mypass"
The password to be used when creating a new ROLE in PostgreSQL.-e "SSH_PUBLIC_KEY=..."
The SSH public key to be added to the authorized_keys file in order to accept SSH connections.
$ docker run -d -p 2223:22 -p 5432:5432 --name postgresql --volume=/mylocaldir:/srv/pgdata -e "PG_USERNAME=myuser" -e "PG_PASSWORD=mypass" -e "SSH_PUBLIC_KEY=..." nimiq/postgresql
A more user-friendly input of the public SSH key:
$ read MY_SSH_KEY < ~/.ssh/id_rsa.pub
$ docker run -d -p 2223:22 -p 5432:5432 --name postgresql --volume=/mylocaldir:/srv/pgdata -e "PG_USERNAME=myuser" -e "PG_PASSWORD=mypass" -e "SSH_PUBLIC_KEY=$MY_SSH_KEY" nimiq/postgresql
Run a one-shot interactive shell:
$ read MY_SSH_KEY < ~/.ssh/id_rsa.pub
$ docker run -ti --rm -p 2223:22 -p 5432:5432 --name postgresql --volume=/mylocaldir:/srv/pgdata -e "PG_USERNAME=myuser" -e "PG_PASSWORD=mypass" -e "SSH_PUBLIC_KEY=$MY_SSH_KEY" nimiq/postgresql /sbin/my_init -- bash
$ docker start postgresql
$ docker stop postgresql
To SSH into the container, run from the host:
ssh [email protected] -p 2223
To connect to the PostgreSQL server, run from the host:
psql -h localhost -p 5432 -U myuser myuser
Key technologies used in Docker-PostgreSQL93:
- Docker
- PostgreSQL
- Bash shell scripting, Linux, Ubuntu, runit
- Baseimage-Docker
- Git, GitHub