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.

Advertisement

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

Add a comment

Leave a Reply

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

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Advertisement