Run PostgreSQL in Docker

To run PostgreSQL on docker, create a directory for saving the data presistant

mkdir -p /opt/my-postgresql

run docker container

docker run --name my-postgresql \
    -p 5432:5432 \
    -e POSTGRES_PASSWORD=serverok123 \
    -e POSTGRES_USER=serverok \
    -e POSTGRES_DB=serverok \
    -v /opt/my-postgresql:/var/lib/postgresql/data \
    -d postgres

In above, change the value for POSTGRES_DB, POSTGRES_USER and POSTGRES_PASSWORD as needed.

Connect to PostgreSQL server

To connect to PostgreSQL server, run

docker container exec -ti my-postgresql bash

Now you are inside PostgreSQL conainer, to login, run

psql -U serverok -W

It will ask for password. Once you enter password, you will be in PostgreSQL command line.

See docker

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *