In this post, I will briefly explain the steps to getup and running PostgreSQL docker image. I have explained in Docker post the basics and how to configure and run MySQL.

Identifying the Image

Let’s begin by searching on DockerHub and pick the official PostgreSQL version.

1
docker pull postgresql:9

If the pull is successful, you must see postgresql in the list of docker images.

1
2
3
4
5
6
7
manju@MANJUTHINK C:\workspace\BLOGS
> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.5 89f8142697a0 10 days ago 255.8 MB
mongo latest 48b8b08dca4d 2 weeks ago 366.4 MB
postgres 9 6f86882e145d 2 weeks ago 265.9 MB
mongo 2.2 8558fe135d54 5 months ago 236.9 MB

Start PostgreSQL

The official documentation touch up on the configuration parameters that are available. Let’s start the server now by exposing it on laptop port 5433.

1
docker run --name pg-server -e POSTGRES_PASSWORD=postgres -v C:/Users/manju/docker/pg:/var/lib/postgresql/ -p5433:5432 -d postgres

Connecting to Server

There are many ways to connect, I usually use PGAdmin. The following commands you can run to run psql from server container.

1
2
3
4
5
docker ps # to obtain the container id
docker exec -it <replace-container-d> bash
psql

Conclusion

Docker makes it really easy to install software on demand. In my opinion Docker is a must have tool in a Test Engineers arsenal.