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.
Go to https://hub.docker.com.
Create an account
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:
Before proceeding, you need to install Docker on your machine if it is not installed locally on your Centos
To install Docker Enterprise (EE), please follow this link:
Otherwise, just install Docker Community Edition (CE) by using the yum command:
Open a command line terminal and start the Docker daemon service:
Go to https://hub.docker.com and search for 'postgres’ :
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.
Open a command line terminal and paste the command "docker pull postgres":
if you want PostgreSQL v11.5, then you need to specify the tag explicitly:
Currently, 11.5 is the latest version, so both commands will pull the same Image.
Enter the command "docker run," which is used to launch container:
Run the command "docker ps" to show the status of the container and all required information:
Run the command "docker exec" to log in to the container:
Here you are able to log in not only to the container but also to the PostgreSQL v11.5 server.
Remove the container once you are done!
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
... View more