How to use Postgres with Docker

 by Robin Wieruch
 - Edit this Post
  • run docker desktop

In your project or in a new project, create a docker-compose.yml file with the following content:

version: '3.8'
services:
postgres:
image: postgres:14.2-alpine
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
POSTGRES_DB: mydatabase
PGDATA: /data/mydatabase
volumes:
- pgstore:/var/lib/postgresql/data
ports:
- '5432:5432'
networks:
- postgres
restart: unless-stopped
pgadmin:
image: dpage/pgadmin4:6.5
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-admin@admin.com}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
volumes:
- pgadmin:/root/.pgadmin
ports:
- '5050:80'
networks:
- postgres
depends_on:
- postgres
restart: unless-stopped
networks:
postgres:
driver: bridge
volumes:
pgstore:
pgadmin:
  • start todo
docker-compose up
  • psql:
docker exec -it node-express-server-rest-api-postgres-1 psql -U <username> <database>
  • pgadmin4

http://localhost:5050/ use your email password combination

Keep reading about 

A collection of all the Docker commands I am using on a regular basis for developing applications with Docker. Docker Machine List all Docker engines: Create a Docker engine: Set environment variables…

Docker Compose helps you run multi-container applications. In this tutorial, we expand a Docker project, which has only a Dockerfile, with Docker Compose. Before you continue, make sure you have set…

The Road to React

Learn React by building real world applications. No setup configuration. No tooling. Plain React in 200+ pages of learning material. Learn React like 50.000+ readers.

Get it on Amazon.