Postgres 9.3 on Ubuntu 12.04 - Fork of pitrho/docker-precise-postgres
394
This repository contains a Dockerfile and associated scripts for building a PostgreSQL Docker image from an Ubuntu 12.04 LTS base image. This particular PostgreSQL Docker image makes it easy to
Clone the repository
export IMGTAG="precise-postgres"
git clone https://github.com/danhixon/precise-postgres.git precise-postgres
cd precise-postgres
docker build -t $IMGTAG .
Verify you have the image locally
docker images | grep "$IMGTAG"
Start the image, creating an admin user "docker" with password "docker".
PGID=$(docker run -d $IMGTAG)
PGIP=$(docker inspect -format='{{.NetworkSettings.IPAddress}}' $PGID)
Now you should be able to connect with psql as such
psql -h $PGIP -U docker -d postgres
You'll get prompted for a password, enter 'docker'. (Clearly, you will need
to have a PostgreSQL client installed to have the psql command.)
A few comments:
-u and -p parameters are passed to the start_postgres.sh shell script, which is the ENTRYPOINT defined in the Dockerfile.start_postgres.sh script.To persist data, you'll need to use Docker volumes.
On the host system, create a directory that will house the persisted data.
mkdir -p /tmp/pgdata
Now, mount that as a volume when you start up the container and tell PostgreSQL to store its data there
PGID=$(docker run -v /tmp/pgdata/:/tmp/pgdata/ -d $IMGTAG -u docker -p docker -d /tmp/pgdata/)
PGIP=$(docker inspect -format='{{.NetworkSettings.IPAddress}}' $PGID)
Again, you can connect from the host system like
psql -h $PGIP -U docker -d postgres
Go ahead and make some changes, e.g. creating a table, etc. Then, stop the container
docker stop $PGID
Now, let's start it up again. Since we created the docker user previously, and
our data were persisted in the volume, there's no need to pass the -u and
-p parameters this time
PGID=$(docker run -v /tmp/pgdata/:/tmp/pgdata/ -d $IMGTAG -d /tmp/pgdata/)
PGIP=$(docker inspect -format='{{.NetworkSettings.IPAddress}}' $PGID)
Now, when you connect to the PostgreSQL instance, you'll notice the changes you made previously are still present.
You can override each of the following PostgreSQL configuration file locations
data_directory,config_file,hba_file, andident_file.To do so, you'll need to put them in a directory that is exposed to the running container as a volume. (The Docker cp command can only copy files from a contain, alas.)
For example, imagine we have a custom PostgreSQL config_file at /tmp/pgconfig/postgresql.conf
and we want to start PostgreSQL using this. We'd start the container like
PGID=$(docker run -v /tmp/pgconfig/:/tmp/pgconfig/ -d $IMGTAG -u docker -p docker -c /tmp/pgconfig/postgresql.conf)
PGIP=$(docker inspect -format='{{.NetworkSettings.IPAddress}}' $PGID)
MIT. See the LICENSE file.
I started with the excellent Precise Postgres Image from Pit Rho.
Content type
Image
Digest
sha256:73e9cb0ac…
Size
105.6 MB
Last updated
about 11 years ago
docker pull danhixon/precise-postgres