A local PostgreSQL development environment based on Docker

  1. Create a directory data in any directory you want.
  2. Create a Docker network using the following command.
docker network create learning-postgreSQL-network 
docker run --rm --name postgres-server -v $(pwd)/data:/var/lib/postgresql/data --network learning-postgreSQL-network -e POSTGRES_PASSWORD=your-password postgres
docker run --rm -it --network learning-postgreSQL-network postgres psql -U postgres -h postgres-server -W
docker run --rm --name postgres-server -v $(pwd)/data:/var/lib/postgresql/data --network learning-postgreSQL-network postgres
  1. A container running a PostgreSQL server.
  2. A client to connect to the PostgreSQL server. The client I want to use is psql. psql is also run in a container.
  3. Data has to be stored locally of course. Any change must be kept in local file system.
docker run --rm --name postgres-server -e POSTGRES_PASSWORD=your-password postgres
docker network create learning-postgreSQL-network
docker run --rm --name postgres-server --network learning-postgreSQL-network -e POSTGRES_PASSWORD=your-password postgres
  • -U designates the user name
  • -h specifies the hostname
  • -W force psql to prompt for a password before connecting to a database
docker run --rm -it --network learning-postgreSQL-network postgres psql -U postgres -h postgres-server -W

One last thing

docker run --rm --name postgres-server -v $(pwd)/data:/var/lib/postgresql/data --network learning-postgreSQL-network -e POSTGRES_PASSWORD=your-password postgres

Another little thing

docker run --rm --name postgres-server -v $(pwd)/data:/var/lib/postgresql/data --network learning-postgreSQL-network postgres

Summary

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Graph Algorithms in Data Structures

Nettols Live Online networking tools |nettools

Corporate audit challenges for hardcoded secrets or passwords in source code

Why did you decide to study Software Engineering?

Git Basic Commands

3 ways to continue using ASK CLI 1.x with the new ASK CLI 2.x

Bootstrap 4: Forms — How to build a contact form for your website

Why Build Progressive Web Apps: Push, but Don’t be Pushy! — Video Write-Up

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
Chun Ming Wang

Chun Ming Wang

More from Medium

Use docker-compose to run PostgreSQL

Relational Database working in 5 minutes

Docker with NodeJS package.json

Simple Dockerfile to build nodejs application

PostgreSQL in a docker container