Very Convenient to Do PostgreSQL Tests With Docker

Photo by Jan Antonin Kolar on Unsplash

Introduction

Let’s try

[root@localhost vagrant]# docker pull postgres:latest
  • Place the file to omit the password for psql
[root@localhost vagrant]# echo "*:5432:*:*:P@ssw0rd_123" >> ~/.pgpass
  • DB server startup
[root@localhost vagrant]# docker run --name test-database -e POSTGRES_PASSWORD=mysecretpassword -d postgres:latest
  • Restore Database
[root@localhost vagrant]# psql -h $(docker inspect --format "{{ .NetworkSettings.IPAddress }}" test-database) -U postgres -f dump.sql
  • Connect to PostgreSQL and test Database
[root@localhost vagrant]# psql -h $(docker inspect --format "{{ .NetworkSettings.IPAddress }}" test-database) -U postgres
  • Stop and remove DB server
[root@localhost vagrant]# docker stop test-database
[root@localhost vagrant]# docker rm test-database
https://giphy.com/

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Maciej

DevOps Consultant. I’m strongly focused on automation, security, and reliability.