How to Deploy PostgreSQL Server Containers on Ubuntu 18.04 using Docker

Hello, welcome to Ubuntu Tutorial. Today I am going to install the PostgreSQL Server Container on Ubuntu 18.04 using Docker. There are several ways to install PostgreSQL on Ubuntu 18.04. But personally, I prefer to install it via Docker. The reason is that its way easier than install using the manual way. Docker Container offers a lightweight and easy way to deploy the robust PostgreSQL Server. I mainly use PostgreSQL to store my GIS and other databases. 


  • Docker on Ubuntu 18.04

Steps to Deploy PostgreSQL Server Containers on Ubuntu 18.04

Before we can deploy the server, we need to install Docker on Ubuntu 18.04. Installing Docker on Ubuntu 18.04 is pretty simple. Follow my previous tutorial from that link above. Once Docker is up and running on Ubuntu, we can start playing around to run PostgreSQL Server.

First, open Terminal and use the following command:

docker run --name postgresql01 --restart=always -e POSTGRES_PASSWORD=12345 -p 54320:5432 -d postgres


–name : Specify the name for our new container. In this case, I name my container as postgresql01.
-p 54320:5432: Expose the specific port. On this example, the port 54320 on the host will be used
-d : The container will run in the background
–restart=always: This will automatically run the container if it stop 
-e POSTGRES_PASSWORD=12345 : Specify the password for postgres superuser. Change the password with a good password

The command will check if the postgres image is available in the localhost. If not, it will pull from the docker hub repository. 

Check the containers

After we run the new container, we can check or list any running containers using ps command

docker ps

Output sample:

b91bed8b26ff postgres "docker-entrypoint.s…" 35 seconds ago Up 18 seconds>5432/tcp postgresql01
80d64ed23baa postgres:latest "docker-entrypoint.s…" 3 weeks ago Up 18 seconds>5432/tcp postgresql
541b14b03d7a portainer/portainer "/portainer" 3 weeks ago Up 18 seconds>9000/tcp portainer

Connect to PostgreSQL Containers

If you follow the above instruction on Ubuntu 18.04, you should be able to connect to the PostgreSQL container from the network. In this example, I use PgAdmin 4 to connect to the container. 

Go to Connection and type the host IP address. 

As you can see, we use port 54320 to connect. 


Deploying PostgreSQL Containers on Docker is pretty easy. But I need to practice more to get a better understanding on Docker. Thanks for reading, and see you on the next tutorials.

Be the first to comment

Leave a Reply