I use docker almost every day (for my development environment) but i don't know why i installed PostgreSQL on my own laptop and not in docker like on my office computer :D. Just for your information, i use Archlinux on my laptop, and i usually got some problems with the regular system update for my PostgreSQL, it tooks me a few hours to fix it that's why i decide to use PostgreSQL database inside docker.
But, i found that by using it on docker is bit different, especially for accessing the PostgreSQL commands since it's being use inside a docker container, so we can't directly use the command through terminal.
I assume you guys already know how to work with docker, and in this article i'll share the basic setup for PostgreSQL database and its tools like PgAdmin through our favorite tool docker compose and terminal. I won't cover any security tips or best configurations since it's only for development, but if you still want to know how to hardening your docker environment for PostgreSQL, please read the documentation.
First step, make sure you have docker and docker compose installed on your machine, then you can pull the PostgreSQL image from docker hub (feel free to choose your own PostgreSQL version), i'm gonna use PostgreSQL 11 and the latest pgadmin4, run
docker pull postgres:11-alpine then
docker pull dpage/pgadmin4.
You can run the following commands in you terminal:
$ mkdir postgres-docker && cd postgres-docker
# Create docker volume for docker
$ docker volume create --driver local --name=postgrevolume
$ docker volume create --driver local --name=pgadminvolume
# Create docker network for docker
$ docker network create --driver bridge postgrenetwork
# Create postgre environment files
$ nano postgre-env.list
$ nano pgadmin-env.list
docker run --publish 5432:5432 \
docker run --publish 8088:80 \
Open your browser to
localhost:8088 and input your pgadmin email and password. Add
new server then set the
postgres container IP address as
host, you can check the IP address through this command
docker container inspect postgres or you can just set
postgres as host since we've run our docker with
We can also use docker compose to wrapped up our services in one file. Create
docker-compose.yml file inside
postgres-docker directory with the following configurations:
Save it and run
docker-compose up -d, it'll work as well as you run directly through
docker run command on terminal.
With this, there will be no problems anymore if i update/upgrade my linux system, i can completely remove PostgreSQL package from my laptop and just using it through docker container. Feel free to send me a feedback on the comment box below, i'll appreciate that.