How to Run Postgresql on Docker (Windows or Mac)
How to setup a local database using docker and postgres
Having Docker Engine installed, open your terminal and run:
docker run --name my-postgres -e POSTGRES_PASSWORD=secretpassword -d -p 5432:5432 postgres
This will first start a download of the official postgresql image from docker hub if you don't have it available locally and then run a container named my-postgres
.
You can now connect to this container using the credentials bellow:
host: localhost
port: 5432
user: postgres
password: secretpassword
database: postgres
How to Stop and Remove a Docker Container
If you want to stop and remove a running container, issue the commands bellow:
docker stop <<container name>>
docker rm <<container name>>
To remove our my-postgres
container issue the commands bellow:
docker stop my-postgres
docker rm my-postgres