Skip to content

Save Time and Effort: Automate PostgreSQL Installation with Docker Compose

How to install PostgreSQL with docker and connect to Universal Database Tool (dBeaver) ?

for using docker, you need to install docker desktop in your local computer See installation. Next successfully install docker, please create file docker compose with name docker-compose.yaml Docker compose file

update it with following content:

version: '3.9'
services:
  postgres:
    image: postgres:14-alpine       # this image is for postgres version 14, if change version, please change here postgres:version (https://hub.docker.com/_/postgres)
    container_name: postgreSQLv14   # container name
    restart: always                 # always restart
    environment:
      - POSTGRES_USER=postgres      # username for database
      - POSTGRES_PASSWORD=postgres  # password for database
      - POSTGRES_DB=my_db           # name of database
    ports:
      - 5432:5432                   # host port 5432 is mapper to docker port 5432
    volumes:
        - postgres-db-volume:/var/lib/postgresql/data
    
volumes:
  postgres-db-volume:
      driver: local
      driver_opts:
          type: none
          o: bind
          device: ./data

next steep running docker compose, please use following command:

    docker-compose up -d

Running docker compose

check your docker container status in docker desktop: Check Docker container status

Connect to Database Tool

This project is using Universal Database Tool (dBeaver community) to connect to PostgreSQL. Please install dBeaver in your local computer See installation. Open dBeaver and click on New Databases Connection tab, and top up form database connection select PostgreSQL and click next button. Select PostgreSQL

enter connection details and click test connection button. connection detail

if test connection success, you can connect to database tool. test connection

click on OK button and click on Finish button, you can connect to database tool. Right click the connection that has been created, then click on connect and the database tool will connect

connect your db connected your db

Good luck and have fun. Enjoy your code.