Each local Divio Cloud project creates a Docker container for its database. 

Your local database and its container

The container name end in _db_1 . If your project is named My Django Project, the container for its database will typically be mydjangoproject_db_1 .

However, you can check using docker ps , which will list the containers. The right-most column will give you the container names.

Running commands in the container

To run commands inside the container, use docker exec.

In the container, the details you will need are:

  • Postgres user: postgres 
  • Postgres database: db 

No password is required.

Thus the general form of commands will be:

docker exec <container name> <command> -U postgres db <operation>

Examples

General

Get the help output from psql :

docker exec mydjangoproject_db_1 psql -U postgres db --help

List databases:

docker exec mydjangoproject_db_1 psql -U postgres --list

Dump and restore

Dump a database to a file named dumped_data  (using pg_dump ):

docker exec mydjangoproject_db_1 pg_dump -U postgres db > dumped_data

To restore a database, apply the SQL commands from a database dump by piping them to through the psql  command:

cat dumpdata | docker exec -i tour20170516_db_1 psql -U postgres db

Other commands

Other Postgres-related commands, such as dropbd , are also available, though it's beyond the scope of this article to provide details of their usage.

Did this answer your question?