Docker PostgreSQL DataBase


$ sudo vi /etc/hosts


127.0.0.1 postgres


.env

DATABASE_HOST=postgres
DATABASE_NAME=postgres-db
DATABASE_PORT=5432
DATABASE_USER=user
DATABASE_PASSWORD=pass123


$ vi docker-compose.yml


version: '3'
services:
  postgres:
    container_name: postgres
    image: postgres:13-alpine
    restart: always
    hostname: ${DATABASE_HOST}
    ports:
      - ${DATABASE_PORT}:5432
    environment:
      POSTGRES_DB: ${DATABASE_NAME}
      POSTGRES_USER: ${DATABASE_USER}
      POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
    volumes:
      - ./PGDATA:/var/lib/postgresql/data


$ docker-compose up


Example:
https://github.com/webmakaka/Uber-Eats-Clone


Run pgadmin in docker container:

$ docker run -e PGADMIN_DEFAULT_EMAIL='[email protected]' -e PGADMIN_DEFAULT_PASSWORD='password1234' -p 5555:80 --name pgadmin dpage/pgadmin4


http://localhost:5555/

login: [email protected]
pass: password1234


To connect, use host ip address