Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

Docker PostgreSQL How-To

How to use zaiste/postgresql Docker container.

Docker >= 0.5.0 required.

docker pull zaiste/postgresql
CONTAINER=$(docker run -d zaiste/postgresql)
CONTAINER_IP=$(docker inspect $CONTAINER | grep IPAddress | awk '{ print $2 }' | tr -d ',"')
psql -h $CONTAINER_IP -p 5432 -d docker -U docker -W
password for user docker:
psql (9.2.4)
Type "help" for help.

docker=# create database foo owner=docker;
CREATE DATABASE
@asbjornenge

This comment has been minimized.

Copy link

@asbjornenge asbjornenge commented Jul 25, 2013

I had to grep for IPAddress when I tried this just now on 0.5.0. Ref my fork. https://gist.github.com/asbjornenge/6078779

@jwarzech

This comment has been minimized.

Copy link

@jwarzech jwarzech commented Aug 6, 2013

I am able to log into psql as the 'docker' user with password 'docker' but it appears that this user doesn't have any permissions to create users or databases. Am I supposed to connect to the shell, start postgres, create my users/db, then create new image?

@zaiste

This comment has been minimized.

Copy link
Owner Author

@zaiste zaiste commented Aug 11, 2013

@asbjornenge thanks I've just corrected the gist

@zaiste

This comment has been minimized.

Copy link
Owner Author

@zaiste zaiste commented Aug 12, 2013

@jwarzech I've just simplified the script and made docker superuser with ability to create roles and databases.

@Painted-Fox

This comment has been minimized.

Copy link

@Painted-Fox Painted-Fox commented Sep 24, 2013

I've got a recommendation for parsing out the ip address.

I installed the jq command line tool like so...

curl -o jq http://stedolan.github.io/jq/download/linux64/jq
chmod +x jq
sudo mv jq /usr/local/bin

Now, instead of using grep, awk, and tr, you can run the following...

CONTAINER_IP=$(sudo docker inspect $POSTGRES_CONTAINER | jq -r '.[0].NetworkSettings.IPAddress')

The -r switch means give the raw output, otherwise the command will put quotes around the ip address.

@binaryphile

This comment has been minimized.

Copy link

@binaryphile binaryphile commented Oct 8, 2013

Just tried running zaiste/postgresql and it immediately exited status one. Jumping on it with /bin/bash and running which postgres gives nothing found, but which psql does show up.

@sym3tri

This comment has been minimized.

Copy link

@sym3tri sym3tri commented Aug 22, 2014

You could also do this to get the IP
$ docker inspect --format='{{.NetworkSettings.IPAddress}}' $INSTANCE_ID

@dragon788

This comment has been minimized.

Copy link

@dragon788 dragon788 commented Mar 14, 2015

Was trying to do the Atlassian Jira in Docker, but getting image invalid for 27cf784147099545 in zaiste/postgresql.

@itainteasy

This comment has been minimized.

Copy link

@itainteasy itainteasy commented Aug 25, 2015

@dragon788

Same error..

[root@localhost atlassian-docker]# docker pull zaiste/postgresql
Trying to pull repository docker.io/zaiste/postgresql ...
0e66fd3d6a6f: Error pulling image (latest) from docker.io/zaiste/postgresql, image ID '27cf784147099545' is invalid 27cf78414709: Error downloading dependent layers failed
Error pulling image (latest) from docker.io/zaiste/postgresql, image ID '27cf784147099545' is invalid

Just grabbing the latest postgresql image does the job
docker search postgresql

Then of course update your docker run command .. we should have used naming adequately.. the wiki is way outdated
docker run -d --name postgres -p=5432:5432 paintedfox/postgresql

The original post that caused some of these questions to be asked is http://blogs.atlassian.com/2013/11/docker-all-the-things-at-atlassian-automation-and-wiring/ ... I'll have to give'em a nudge as well as zaiste's docker image in the repo (https://hub.docker.com/r/zaiste/postgresql/).

Best of luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment