cancel
Showing results for 
Search instead for 
Did you mean: 

How to run PostgreSQL on Docker?

EDB Team Member

How to run PostgreSQL on Docker?

 

 

Docker is an open source platform where we can create, deploy, and run applications by using containers. Docker is similar to virtual machines (VM), but in VM you need to create a virtual operating system, while Docker allows applications to use the system kernel.

 

PostgreSQL community supports (v9.4,v9.5, v9.6, v10, v11 etc.) Images.

The difference between Images and containers is that Images are simply templates of instructions, and an instance of an Image is called a container.

 

Here are some helpful definitions

================

Docker: a tool/platform.

Image: an application that we want to create/deploy.  (In this case, we want to deploy the PostgreSQL v. 11.5 (latest release as of August 28, 2019) Image.)

Container: runs an instance of an Image (template of instructions).

 

Step-by-Step guide to deploying a PostgreSQL Image on Docker 

============================================

     0. Use a CentOS 7 64-bit machine.

  1. Go to  https://hub.docker.com.
  2. Create an account

snapshot_2.png

After pressing Continue, it will ask you for your first name, last name, and some related personal questions. Press Continue,  and it will then ask you to check your inbox and verify your email address. Once you’ve done that, congrats! You are registered on the site, and your DockerID is created.

 

    3. Sign in to your account:



snapshot_3.png




  1. Before proceeding, you need to install Docker on your machine if it is not installed locally on your Centos 


snapshot_4.png


  1. To install Docker Enterprise (EE), please follow this link: 

https://docs.docker.com/install/linux/docker-ee/centos/#find-your-docker-ee-repo-url

 

Otherwise, just install Docker Community Edition (CE) by using the yum command: 



snapshot_5.png



  1. Open a command line terminal and start the Docker daemon service:

snapshot_6.png



  1. Go to https://hub.docker.com and search for 'postgres’ :


snapshot_7.png



  1. All the PostgreSQL server Official Images can be found there. On the right-hand side of the page, there is a command to pull the Image: "docker pull postgres."  Copy it.


snapshot_8.png



  1. Open a command line terminal and paste the command "docker pull postgres":


snapshot_9.png

OR



  1. if you want PostgreSQL v11.5, then you need to specify the tag explicitly: 


snapshot_10.png


Currently, 11.5 is the latest version, so both commands will pull the same Image.

 

  1. Enter the command "docker run," which is used to launch container: 


snapshot_11.png


  1. Run the command "docker ps" to show the status of the container and all required information: 


snapshot_12.png


  1. Run the command "docker exec" to log in to the container:

snapshot_13.png

Here you are able to log in not only to the container but also to the PostgreSQL v11.5 server. 

 

  1. Remove the container once you are done!

snapshot_14.png


Hope this helps!

 

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

 

____________________________________

 

Article originally posted Thursday, August 29, 2019 at - https://tusharah.blogspot.com/2019/08/how-to-run-postgresql-on-docker.html