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

View File

@ -13,8 +13,11 @@ services:
restart: unless-stopped restart: unless-stopped
networks: networks:
- pg-net - pg-net
#ipv4_address: 192.168.100.2
ports:
- 10500:5432
healthcheck: healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"] test: ["CMD-SHELL", "pg_isready -U kolchin"]
interval: 5s interval: 5s
timeout: 10s timeout: 10s
retries: 3 retries: 3
@ -29,23 +32,29 @@ services:
restart: unless-stopped restart: unless-stopped
networks: networks:
- pg-net - 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: depends_on:
pg: pg:
condition: service_healthy 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: volumes:
pg-data: pg-data:
networks: networks:
pg-net: pg-net:
#driver: bridge
#ipam:
# config:
# - subnet: 192.168.100.0/24
# - gateway: 192.168.100.1