Postgresql on Ubuntu - Forked pitrho/docker-precise-postgres
651
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-9.3"
git clone https://github.com/danhixon/precise-postgres.git
cd precise-postgres
docker build -t $IMGTAG .
Verify you have the image locally
docker images | grep "$IMGTAG"
Start the image, creating an admin user "foo" with password "bar".
PGID=$(docker run -d $IMGTAG -u foo -p bar)
PGIP=$(docker inspect -format='{{.NetworkSettings.IPAddress}}' $PGID)
Now you should be able to connect with psql as such
psql -h $PGIP -U foo -d postgres
You'll get prompted for a password, enter 'bar'. (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 foo -p bar -d /tmp/pgdata/)
PGIP=$(docker inspect -format='{{.NetworkSettings.IPAddress}}' $PGID)
Again, you can connect from the host system like
psql -h $PGIP -U foo -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 foo 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 foo -p bar -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:d6fc238c4…
Size
100.6 MB
Last updated
almost 11 years ago
docker pull danhixon/ubuntu-postgres