Create a Postgres Database from scratch in 5 minutes

Create a Docker volume as data storage

docker volume create pgdata
docker volume lsDRIVER    VOLUME NAME
local pgdata

Create a new Postgres Docker container

docker run --name postgres-dev -e POSTGRES_PASSWORD=my_postgres_password -d -p 54320:5432 -v pgdata:/var/lib/postgresql/data postgres
docker psCONTAINER ID   IMAGE      COMMAND                  CREATED         STATUS         PORTS                     NAMES
9b6baf4970cc postgres "docker-entrypoint.s…" 4 seconds ago Up 4 seconds 0.0.0.0:54320->5432/tcp postgres-dev
docker exec -it postgres-dev psql -U postgrespsql (13.1 (Debian 13.1–1.pgdg100+1))
Type “help” for help.
postgres=#

Create a new Database

docker exec -i postgres-dev psql -U postgres -c "CREATE DATABASE golinks WITH ENCODING='UTF8' OWNER=postgres;"CREATE DATABASE
docker exec -it postgres-dev psql -U postgres
psql (13.1 (Debian 13.1-1.pgdg100+1))
Type "help" for help.

postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+------------+------------+-----------------------
golinks | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
postgres=#

--

--

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