# Run Postgres on docker

### Prerequisite

1.  Install [docker](https://docs.docker.com/install/linux/docker-ce/ubuntu/)
2.  Install [docker-compose](https://docs.docker.com/compose/install/)

### Deploying Postgres Container

We will create a ***docker-compose.yml*** configured with postgres

OR

Run the following command to run postgres docker-container

docker-compose up -d 

OR

docker stack deploy

To check the services runing use

docker ps -a # to checlk the services running  
docker logs postgress-service

#### Import/Restore SQL

Create a .sql file

cat create-databases-dev.sql | docker exec -i postgress-service psql -U test

#### Export/Backup SQL

docker exec -t -u test postgress-service pg\_dumpall -c > dump\_\`date +%d-%m-%Y"\_"%H\_%M\_%S\`.sql

If you want to go with adminer follow use the below docker-compose file

Postgres with adminer UI

#### Reference

[https://github.com/JinnaBalu/postgreSQL](https://github.com/JinnaBalu/postgreSQL)

[**postgres - Docker Hub**  
*The PostgreSQL object-relational database system provides reliability and data integrity.*hub.docker.com](https://hub.docker.com/_/postgres "https://hub.docker.com/_/postgres")[](https://hub.docker.com/_/postgres)

[**Adminer - Database management in a single PHP file**  
*Adminer (formerly phpMinAdmin) is a full-featured database management tool written in PHP. Conversely to phpMyAdmin, it…*www.adminer.org](http://www.adminer.org/ "http://www.adminer.org/")[](http://www.adminer.org/)
