postgresql: Add PostgreSQL container instructions (Dockerfile and README)
[dockerfile.git] / postgresql / README.md
1 Run this [PostgreSQL][] image with:
2
3     $ docker run -d -name postgresql-0 wking/postgresql
4
5 Then [link][linking] to it from your client container:
6
7     $ docker run -link postgresql-0:postgresql your-client
8
9 For example, we can use the PostgreSQL client in the
10 `wking/postgresql` image itself:
11
12     $ docker run -link postgresql-0:postgresql -i -t wking/postgresql /bin/bash
13     94ca64e60a00 / # HOST_PORT="${POSTGRESQL_PORT#[a-z]*://}"
14     94ca64e60a00 / # HOST="${HOST_PORT%:[0-9]*}"
15     94ca64e60a00 / # PORT="${HOST_PORT#[0-9.]*:}"
16     94ca64e60a00 / # psql -h "${HOST}" -p "${PORT}" -U postgres
17     psql (9.2.4)
18     Type "help" for help.
19
20     postgres=# help
21     You are using psql, the command-line interface to PostgreSQL.
22     …
23
24 The exposed port is not proxied by the host:
25
26     $ docker port postgresql-0 5432
27     2013/12/12 15:56:28 Error: No public port '5432' published for postgresql-0
28
29 But you can access it if you know the IP:
30
31     $ psql -h 10.0.0.12 -p 5432 -U postgres
32     psql (9.2.4)
33     Type "help" for help.
34
35     postgres=#
36
37 You can also access it from unlinked containers:
38
39     $ docker run -i -t wking/postgresql /bin/bash
40     8ee7a0597619 / # psql -h 10.0.0.12 -p 5432 -U postgres
41     psql (9.2.4)
42     Type "help" for help.
43
44     postgres=# …
45
46 Basically, anyone with access to the `docker0` bridge has access to
47 the client's port.
48
49 [PostgreSQL]: http://postgresql.io/
50 [linking]: http://docs.docker.io/en/latest/use/port_redirection/#linking-a-container