problems net

This commit is contained in:
sanek 2024-12-11 21:21:29 +00:00
parent 5cd649b741
commit 1e9422f836
2 changed files with 39 additions and 33 deletions

21
app.py
View File

@ -1,8 +1,6 @@
import psycopg2
print('Can`t establish connection to database')
'''
try:
conn = psycopg2.connect(
dbname="kolchin",
user="kolchin",
@ -10,16 +8,15 @@ conn = psycopg2.connect(
host="pg",
port="5432"
)
except:
print('Can`t establish connection to database')
#print(conn)
cursor = conn.cursor()
with conn.cursor() as curs:
curs.execute(CREATE TABLE IF NOT EXISTS tablee(
name varchar(10) NOT NULL,
surname varchar,
city varchar,
age smallint
);)
cursor.execute('CREATE TABLE IF NOT EXISTS tablee(name varchar(10) NOT NULL,surname varchar,city varchar,age smallint);')
conn.commit()
conn.close()
'''
cursor.close() # закрываем курсор
conn.close() # закрываем соединение

View File

@ -13,8 +13,11 @@ services:
restart: unless-stopped
networks:
- pg-net
#ipv4_address: 192.168.100.2
ports:
- 10500:5432
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
test: ["CMD-SHELL", "pg_isready -U kolchin"]
interval: 5s
timeout: 10s
retries: 3
@ -29,23 +32,29 @@ services:
restart: unless-stopped
networks:
- pg-net
#ipv4_address: 192.168.100.3
depends_on:
pg:
condition: service_healthy
app:
build:
context: ./
args:
PYTHON_VERSION: "3.10"
UID: 10002
container_name: python-app
networks:
- pg-net
#ipv4_address: 192.168.100.4
depends_on:
pg:
condition: service_healthy
# app:
# build:
# context: ./
# args:
# PYTHON_VERSION: "3.10"
# UID: 10002
# container_name: python-app
# networks:
# - pg-net
# depends_on:
# pg:
# condition: service_healthy
volumes:
pg-data:
networks:
pg-net:
#driver: bridge
#ipam:
# config:
# - subnet: 192.168.100.0/24
# - gateway: 192.168.100.1