728x90
백업을 위한 볼륨
docker volume create pgdata
---
version: '3'
services:
postgre_my:
image: postgres
container_name: postgre_my
ports:
- "8501:5432"
environment:
POSTGRES_PASSWORD: mypw
volumes:
- pgdata:/var/lib/postgresql/data
pgadmin:
image: dpage/pgadmin4
container_name: pgadmin
ports:
- "8080:80"
environment:
PGADMIN_DEFAULT_EMAIL: my@test.com
PGADMIN_DEFAULT_PASSWORD: mypw
depends_on:
- postgre_my
volumes:
pgdata:
external: true
---
* pgadmin
http://host_ip:8080/
id : my@test.com
pw : mypw
- new server
Hostname/address: postgre_my
Port: 5432
Maintenance database: postgres
Username: postgres
Password: mypw
파이썬 연결 테스트
import psycopg2
try:
conn = psycopg2.connect(dbname='postgres', user='postgres', password='mypw', host='127.0.0.1', port='8501')
cur = conn.cursor()
cur.execute('SELECT version()')
print('PostgreSQL version:', cur.fetchone())
except Exception as e:
print('Error:', e)
finally:
conn and conn.close()
5432 포트를 외부에서 사용시
728x90
'Python' 카테고리의 다른 글
ORM 방식으로 db에 데이터 추가하 (0) | 2023.12.15 |
---|---|
스플렁크 쿼리 결과 가져오기 (0) | 2023.11.10 |
깨진 링크 검사기 (broken link checker) (0) | 2023.08.23 |
yield 한 방에 이해하기 (0) | 2023.08.04 |
edge-tts 사용해보기 (0) | 2023.07.21 |