Running a PostgreSQL server
orchardup/postgresql image lets you start a PostgreSQL server in a matter of seconds. First, create your default Docker host if it isn’t already running:
$ orchard hosts create Default host running at 188.8.131.52
Choose a password for the database user by replacing yourpassword with a password of your choice.
$ orchard docker run -d -p 5432:5432 -e POSTGRESQL_USER=test -e POSTGRESQL_PASS=yourpassword orchardup/postgresql Pulling image orchardup/postgresql 346ba74f52 $ orchard docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS b96c70cc97e4 orchardup/postgresql:latest /usr/local/bin/run 21 seconds ago Up 15 seconds 0.0.0.0:5432->5432/tcp
Two things to note:
- There’s no need to pass a run command, because the image specifies a default.
- We’re exposing PostgreSQL’s port (5432) on the container to the same port on the host.
We now have a running PostgreSQL instance, and can use the PostgreSQL client commands (if we have them installed locally) to talk to it. The image we used created a user called test with the password you chose above.
First, let's create a database to use:
$ createdb -h 184.108.40.206 -U test foo
Next, we can connect to the database using the
$ psql -h 220.127.116.11 -U test foo Password for user test: psql (9.3.0, server 9.2.4) SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256) Type "help" for help. foo=# create table things (name varchar(255)); CREATE TABLE foo=# insert into things (name) values ('soup'); INSERT 0 1 foo=# select * from things; name ------ soup (1 row) foo=# \q
We can also get the contents of the database out with
$ pg_dump -h 18.104.22.168 -U test foo Password: ...SQL data dump...
We can stop the container using its ID (or a prefix of it):
$ orchard docker kill b96c70cc97e4 b96c70cc97e4
Finally, hosts are charged based on how long they’re around for, so if you’re done, you can remove it:
$ orchard hosts rm