Setup a PostgreSql Database in DigitalOcean droplet

# install docker 
apt install docker.io
# verify installation by checking the version
docker -v
# you will get output something like below -
Docker version 20.10.12, build 20.10.12-0ubuntu4
# pull postgres docker image
docker pull postgres:latest
# up the postgres container
docker run -itd -e POSTGRES_USER=<user> \
-e POSTGRES_PASSWORD=<pwd> \
-p 5432:5432 \
-v /data:/var/lib/postgresql/data \
--name postgresql postgres
# you will get the container id in return, check the logs nowdocker logs -f <container_id># on success, you will see similar entry in log
2022-07-20 09:38:07.841 UTC [1] LOG: database system is ready to accept connections
# install ngrok
snap install ngrok
# start tunnel
ngrok tcp 5432
# add auth token
ngrok config add-authtoken <token>
# now start tcp tunnel in background
ngrok tcp 5432 --log=stdout > ngrok.log &
# open the log file. you will see the forwarding url
# url=tcp://0.tcp.in.ngrok.io:13593
# 0.tcp.in.ngrok.io - db server host
# 13593 - port

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store