PostgreSQL database as a docker container

Any technology enthusiast who love to explore new developments in the technology landscape would have come across situations where you would want to have a SQL database with the minimum effort .

PostgreSQL is a good choice in such situations to spin up a lightweight database , which you can even run a docker container.

In this post we are going to set up a docker-compose file for starting up a docker container of PostgreSQL .

Create the docker-compose.yml file in the project root and define the details as given below

version: '3'
image: library/postgres:latest
- "5432:5432"
container_name: aiport-db-postgres
- POSTGRES_DB= airport-db
- ./data:/var/lib/postgresql
- ./init.sql:/docker-entrypoint-initdb.d/init.sql

As you can see we have included an init.sql file which has the database script to create a database objects and to initialise the data.

contents of init.sql is as given below

CREATE TABLE public.airport (
id bigint NOT NULL,
apt_code character varying(255),
apt_name text,
city_name text,
country text

To start the data base use the docker compose up command

docker-compose up

Your PostegreSQL DB with the data base objects defined in the init.sql will be up and running in no time.

Techie , Travelista ,Philomath

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