Thursday, August 29, 2019

How to run PostgreSQL on Docker ?

Docker is a Open source tool/platform where we can create/deploy/run application by using containers.Docker is similar to VM but in VM - one need to create virtual operating system but in case of Docker  -it will allow applications to use system kernel where it is running on.

PostgreSQL community supports PG (v9,4,v9,5,v9.6,v10,v11 e.t.c) Images
The difference between images and container is -
Image is nothing but a template of instructions and  an instance of an image is called Container.

so here is what is what -
================
Docker- is a tool/platform.
Image- is an application which we want to create/deploy  e.g In this case we want to deploy  PG v11.5(latest released as on 28th/Aug/2019)  Image.
Container - Running instance of an image (template of instructions) .

Steps by Steps guide to deploy PostgreSQL image on Docker 
============================================
0. Centos 7 64 bit machine
1.Go to  https://hub.docker.com/
2.Create a login account (Sign up)


After Pressing continue -it will ask you - your  first name/last name /your profile  and  some other crap questions.  - Press Continue - it will further ask you to check your inbox and click on "Confirm your email with Docker "  , Once you done that -
Congrats - You are registered on the site and your DockerID is created.

Sign up time -





















First thing ,We need to install docker on machine , right now it is not installed locally on my Centos 7










3.To install Docker Enterprise(EE) , Please follow this link - 

Otherwise , just  install Docker CE(Community edition) by using yum command 










Open a command line terminal and start the docker daemon service -












4.Go to https://hub.docker.com and write 'postgres' in search box 















All the official PG server images can be found that and on the right hand side, there is a command to pull the image i.e "docker pull postgres" , copy it .












5.Open a command line terminal and paste command - "docker pull postgres"












OR


if we want PG v11.5 then we need to specify the tag explicitly i.e 








Currently latest is 11.5 only so both are same.

6.Run "docker run" command which is used to launch container 






7.Run "docker ps" command which shows status of container and all required information 




8.Run "docker exec" command which is used to login to the container

Here, if we see - We are not only able to login to the container but also login to PG v11.5 server 

9.Remove the  container once you are done !



Hope this helps!

I would like to  thanks my colleague Mr.Jitendra Wadle for all his help and assistance.  


1 comment:

Anonymous said...

detailed steps, helpful.

Post a Comment